Skip to content

Raise JSONDecodeError instead of ValueError when passing invalid JSON? #118

Description

@maxalbert

The json module in the Python standard library raises a JSONDecodeError if invalid JSON is passed to json.loads(), while rapidjson raises a ValueError.

This inconsistency means you can't easily swap import json for import rapidjson as json if you are catching possible JSONDecodeError exceptions.

Would it be possible for rapidjson to raise a JSONDecodeError instead of a ValueError?

Example to reproduce:

>>> import json
>>> json.loads('{'})
JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 2 (char 1)

vs.

>>> import rapidjson
>>> rapidjson.loads('{'})
ValueError: Parse error at offset 1: Missing a name for object member.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions