Merge JSON objects using jq
Merging objects in jq
is handled natively since 1.14.
Merge objects using jq
Given a file named example.json
1{
2 "key": "value1",
3 "anotherKey": "value2",
4 "oneMoreKey": "value3"
5}
and another file named example2.json
,
1{
2 "key1": "value2",
3 "key2": "value3",
4 "key4": "value4"
5}
merging the two objects can be completed using:
1jq -s '.[0] * .[1]' example.json example2.json
Output:
1{
2 "key1": "value2",
3 "key2": "value3",
4 "key4": "value4",
5 "key": "value1",
6 "anotherKey": "value2",
7 "oneMoreKey": "value3"
8}