3

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?

oguz ismail
  • 1
  • 16
  • 47
  • 69
Srinivas B
  • 35
  • 6
  • 1
    Related: [Does “argument list too long” restriction apply to shell builtins?](https://stackoverflow.com/q/47443380/6862601). – codeforester Jan 28 '21 at 10:04

1 Answers1

5

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 .
oguz ismail
  • 1
  • 16
  • 47
  • 69