14

I have multiple JSON Files with the same structure , the list is the array.

$ jq 'keys' file_1.json
[
  "itemsPerPage",
  "links",
  "list",
  "startIndex"
]

the list field looks like this

file1.json

 "list" : [ {"id: 123, "fname":"SAM" }, {"id: 125, "fname":"JOE" } .....]

fileX.json

 "list" : [ {"id: 783, "fname":"Danny" }, {"id: 785, "fname":"Kingmo" } .....]

trying to generate an output as follows (Only List and Ignoring other fields which are itemsPerPage/links/startIndex)

 "list" : [ {"id: 123, "fname":"SAM" }, {"id: 125, "fname":"JOE" },  {"id: 783, "fname":"Danny" }, {"id: 785, "fname":"Kingmo" }]

what's the best way to read all those files in with jq and generate a single file with one list array that has all the objects from all the JSON files ?

1 Answer 1

23

You can use inputs function to get the content of all the JSON files together and append only the .list field together

jq -n '{ list: [ inputs.list ] | add }' file1.json file2.json
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .