"Argument list too long" while slurping JSON files

Viewed 302

I have thousands of JSON files, and I want to merge them into a single one. I'm using the command below to do this.

jq -s . -- *.json > result.json

But I am getting argument list too long error, probably because of the number of files I'm trying to merge. Is there any workaround for this issue?

1 Answers

Built-in commands are immune to that limitation, and printf is one of them. In conjunction with xargs, it would help a lot to achieve this.

printf '%s\0' *.json | xargs -0 cat -- | jq -s .
Related