Using jq to combine multiple JSON files Using jq to combine multiple JSON files json json

Using jq to combine multiple JSON files


To merge the .data elements of all the responses into the first response, you could run:

jq 'reduce inputs.data as $s (.; .data += $s)' page1.json page2.json ...

Alternatives

You could use the following filter in conjunction with the -n command-line option:

reduce inputs as $s (input; .data += ($s.data))

Or if you simply want an object of the form {"data": [ ... ]} then (again assuming you invoke jq with the -n command-line option) the following jq filter would suffice:

{data: [inputs.data] | add}


Just to provide closure, @peak provided the solution. I am using it in conjunction with the method found here for using wildcards in batch files to address multiple files. The code looks like this now:

set expanded_list=for /f "tokens=*" %%F in ('dir /b /a:-d "All Cards\!setname!_*.json"') do call set expanded_list=!expanded_list! "All Cards\%%F"jq-win32 "reduce inputs.data as $s (.; .data += $s)" !expanded_list! > "All Cards\!setname!.json"

All the individual pages for each card set are named "setname"_"pagenumber".json

The code finds all the pages for each set and combines them into one variable which I can pass into jq.

Thanks again!