Quantcast
Channel: Active questions tagged jq - Stack Overflow
Viewing all articles
Browse latest Browse all 524

Combine an arbitrary number of JSON files with jq

$
0
0

I can combine 2 json files using jq, thus:

jq -s '.[0] * .[1]' file1.json file2.json >merged.json

I can combine an arbitrary number of json files by using a loop and on the second and subsequent iterations, used the output of the previous operation as one of the inputs. And with process substitution, that can be done via a pipe:

jq -s '.[0] * .[1]' file1.json file2.json | \   jq -s '.[0] * .[1]'<(cat) file3.json | \   jq -s '.[0] * .[1]'<(cat) file4.json ...

But how can I script merging of an arbitrary number of files without writing intermediate versions?

(I imagine that with a VERY large number of files I will have issues with ulimits / file handles - I am not concerned about that yet).


Viewing all articles
Browse latest Browse all 524

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>