skip to Main Content

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


  1. Chosen as BEST ANSWER

    Workaround is to use another tool, e.g. jj, which does the job perfectly, and probably also faster in general, even if jq doesn't error.

    jj -u <input.json >minified.json
    

    Binaries available at: https://github.com/tidwall/jj/releases/latest or via homebrew:

    brew install tidwall/jj/jj
    

  2. 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:

    #define MAX_PARSING_DEPTH (256)
    

    As best I can tell, there does not seem to be any downside to increasing the limit to a very large number.

    Login or Signup to reply.
  3. 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 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:

       jj -u @this < input.json
       jm input.json
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search