Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Join the 2 json report using jq

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
  "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

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading