This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Document maximum JSON depth or remove it.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: boris, rhettinger
Priority: normal Keywords:

Created on 2019-11-09 00:22 by boris, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg356276 - (view) Author: Борис Верховский (boris) * Date: 2019-11-09 00:22
import json

foo = {}

for i in range(1000):
    json.dumps(foo)
    print(i)
    foo = {'bar': foo}


Will error at 994. At a minimum this magic number should be documented, but it would be better if the json library could handle arbitrarily nested JSON or have a configurable limit.

https://github.com/lovasoa/bad_json_parsers
msg356339 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2019-11-10 21:59
There is nothing here specific to JSON.  It is Python's normal (and documented) limit on recursion. 

If needed, you can change the limit to as large as needed:

    import json
    import sys
    sys.setrecursionlimit(50_000)

    foo = {}

    for i in range(10_000):
        foo = {'bar': foo}
    s = json.dumps(foo)
    print(len(s))
History
Date User Action Args
2022-04-11 14:59:23adminsetgithub: 82932
2019-11-10 22:00:09rhettingersetstatus: open -> closed
resolution: not a bug
stage: resolved
2019-11-10 21:59:56rhettingersetnosy: + rhettinger
messages: + msg356339
2019-11-09 00:22:59boriscreate