I am using jq tools (jq-json-processor) in a shell script to parse json.
I have 2 json files and want to merge them into one unique file
Here are the contents of the files:
file1
{ "value1": 200, "timestamp": 1382461861, "value": { "aaa": { "value1": "v1", "value2": "v2" }, "bbb": { "value1": "v1", "value2": "v2" }, "ccc": { "value1": "v1", "value2": "v2" } } }
file2
{ "status": 200, "timestamp": 1382461861, "value": { "aaa": { "value3": "v3", "value4": 4 }, "bbb": { "value3": "v3" }, "ddd": { "value3": "v3", "value4": 4 } } }
Expected Result
{ "value": { "aaa": { "value1": "v1", "value2": "v2", "value3": "v3", "value4": 4 }, "bbb": { "value1": "v1", "value2": "v2", "value3": "v3" }, "ccc": { "value1": "v1", "value2": "v2" }, "ddd": { "value3": "v3", "value4": 4 } } }
I try to combine a lot, but the only result I get is the following: this is not the expected result:
{ "ccc": { "value2": "v2", "value1": "v1" }, "bbb": { "value2": "v2", "value1": "v1" }, "aaa": { "value2": "v2", "value1": "v1" } } { "ddd": { "value4": 4, "value3": "v3" }, "bbb": { "value3": "v3" }, "aaa": { "value4": 4, "value3": "v3" } }
With this command:
jq -s '.[].value' file1 file2