I have 2 report files like the following
report1.json
{
"examples": [
{
"description": "desc 1",
"full_description": "full_description 1",
"status": "status 1",
"file_path": "file_path 1",
"run_time": 0.01
}
]
}
and report2.json
{
"examples": [
{
"description": "desc 2",
"full_description": "full_description 2",
"status": "status 2",
"file_path": "file_path 2",
"run_time": 0.02
}
]
}
I want to combine it using jq command with hope the end result is as follows
{
"examples": [
{
"description": "desc 1",
"full_description": "full_description 1",
"status": "status 1",
"file_path": "file_path 1",
"run_time": 0.01
},
{
"description": "desc 2",
"full_description": "full_description 2",
"status": "status 2",
"file_path": "file_path 2",
"run_time": 0.02
}
]
}
i have tried using this script jq -s ‘.[0] * .[1]’ report1.json report2.json but it doesn’t work, is there any solution to be able to combine according to my expected result using jq command ?
>Solution :
Try this:
jq -s ' [ (.[0] | keys[]) as $k | reduce .[] as $item (null; .[$k] += $item[$k]) ] | add' report1.json report2.json
