Title: Document maximum JSON depth or remove it.
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
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 2019-11-10 22:00 by rhettinger. 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):
    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.
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

    foo = {}

    for i in range(10_000):
        foo = {'bar': foo}
    s = json.dumps(foo)
Date User Action Args
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