Reducing JSON with jq
To expand on the other two answers a bit, you can "add" two objects together like this:
.[0] + .[1]=> { "key1": "value", "key2": "value" }
You can use the generic reduce
function to repeatedly apply a function between the first two items of a list, then between that result and the next item, and so on:
reduce .[] as $item ({}; . + $item)
We start with {}
, add .[0]
, then add .[1]
etc.
Finally, as a convenience, jq has an add
function which is essentially an alias for exactly this function, so you can write the whole thing as:
add
Or, as a complete command line:
jq add myjson.json