Skip to content

JSON parse difference from CPython #10446

Open
@FoamyGuy

Description

@FoamyGuy

adafruit/Adafruit_Learning_System_Guides#3067 reported some malformed JSON in a config file used by the EZ Make oven project.

While looking into this I realized that the incorrect JSON didn't cause the code to stop working and led to the realization that JSON parsing seems to be more forgiving at least in the case of a missing comma between child list items

For comparison here is a simplified reproducer, there is a missing comma between [2,3] and the [1,2] that follows

Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> json.loads('{"l": [[1,2], [1,2], [2,3] [1,2], [3, 4]]}')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3.12/json/__init__.py", line 346, in loads
    return _default_decoder.decode(s)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.12/json/decoder.py", line 353, in raw_decode
    obj, end = self.scan_once(s, idx)
               ^^^^^^^^^^^^^^^^^^^^^^
json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 28 (char 27)

Adafruit CircuitPython 10.0.0-alpha.7 on 2025-06-17; Adafruit PyPortal with samd51j20
>>> import json
>>> json.loads('{"l": [[1,2], [1,2], [2,3] [1,2], [3, 4]]}')
{'l': [[1, 2], [1, 2], [2, 3], [1, 2], [3, 4]]}

I didn't see an issue that covered this difference in behavior so created this to raise it and see if we would want to change the behavior to match CPython or if it's perhaps just a code size trade off for simplified parsing logic that isn't as good at catching some types of malformed input.

I'm not sure the difference is that big of a deal personally, but figured it's worth checking whether it's known/intentional or if we'd want to change it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions