I have a json file which I am fetching from consul and the results are very simple:
[ { "name" : Jon", "class" : "senior" } ]
I want to update the array with below json:
{ "name" : santa", "class" : "christmas" }
and the output should be:
[ { "name" : Jon", "class" : "senior" }, { "name" : santa", "class" : "christmas" } ]
This looks very simple but I am unable to do it till now.
this is what I have been trying with jq
:
JSON=[{ "name" : Jon", "class" : "senior" }]
echo $JSON | jq '.[] += { "new_key" : "new_value" }'
I followed some answers on stackoverflow but most of them are about adding a single element.