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.
The
jsonmodule in the Python standard library raises aJSONDecodeErrorif invalid JSON is passed tojson.loads(), whilerapidjsonraises aValueError.This inconsistency means you can't easily swap
import jsonforimport rapidjson as jsonif you are catching possibleJSONDecodeErrorexceptions.Would it be possible for
rapidjsonto raise aJSONDecodeErrorinstead of aValueError?Example to reproduce:
vs.