When trying to minify a deeply nested JSON file (~10k deep) using jq
I got a parse error:
$ jq -c . <input.json >minified.json
parse error: Exceeds depth limit for parsing at line 227263, column 355
How can I increase the depth limit? Is there a command line option? I couldn’t find anything about this in the man page.
3
Answers
Workaround is to use another tool, e.g.
jj
, which does the job perfectly, and probably also faster in general, even ifjq
doesn't error.Binaries available at: https://github.com/tidwall/jj/releases/latest or via homebrew:
Regarding the C implementation, you’d have to remake the binary after changing MAX_PARSING_DEPTH in jv_parse.c, in which the relevant line is currently:
As best I can tell, there does not seem to be any downside to increasing the limit to a very large number.
gojq (the Go implementation of jq) has a limit on the maximum depth it can handle: it’s greater than 1,024 but less than 10,000.
I’ve verified that jj and my "JSON Machine"-based utility, jm, can both handle a depth of 10,000. The following are equivalent ways of compactifying a JSON document, at least if the limit isn’t breached: