Skip to content

Unhelpful parse error in decoder.py #127339

Closed as not planned
Closed as not planned
@Smit-tay

Description

@Smit-tay

Bug report

Bug description:

This is the essentially useless output from attempting to parse a malformed json :

File "/usr/lib/python3.10/json/decoder.py", line 355, in raw_decode
    raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

In my case the json file - written by hand - looked something like this:

### A comment here
{
    "name": "value"
}

As you can see, the first line is invalid JSON, since, for reasons left to be imagined, the designers of JSON didn't like long existing UNIX standard comment indicators.

I suspect a more usefull error message when parsing might be something like :
json.decoder.JSONDecodeError: Invalid JSON "### A comment here" , Expecting value: line 1 column 1 (char 0)

This at least gives someone NOT INTERESTED in opening a debugger - i.e. a naive and casual user - a hint that the JSON is malformed - somehow.

CPython versions tested on:

3.10

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions