Reputation: 787
Is there a simple way to combine two json variables?
Given $a {a:1,b:1}
and $b {c:1,d:1}
How do I produce a result of {a:1,b:1,c:1,d:1}
Upvotes: 2
Views: 3544
Reputation: 117027
Yes, e.g.
$a + $b
or
[$a,$b]|add
For example, if $a and $b are initially JSON-valued shell variables:
jq -n --argjson a "$a" --argjson b "$b" '$a + $b'
Upvotes: 5
Reputation: 13939
Try the following:
a='{"a":1,"b":1}'
b='{"c":1,"d":1}'
jq --slurp 'add' <(echo "$a") <(echo "$b")
Output:
{
"a": 1,
"b": 1,
"c": 1,
"d": 1
}
Upvotes: 2