1

here are 3 JSON files

File1

{
  "component1": [
  ]
}

File2

{
  "component2": [
  ]
}

File3

{
  "component3": [
  ]
}

Don't find the jq command line that would give this JSON file as jq output:

{
  "components": {
     "component1": [
      ],
     "component2": [
      ],
     "component3": [
      ]
   }
}

Many thanks for your support Best Regards.

2 Answers 2

1

Iterate over the input objects one a time from inputs and append it to the components using the reduce function

jq -n 'reduce inputs as $d (.; .components += $d )' file{1..3}.json
Sign up to request clarification or add additional context in comments.

Comments

1

You can simply use add, e.g.

jq -s '{components: add}' file{1..3}.json

or:

jq -n '{components: [inputs]|add}' file{1..3}.json

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.