[docs] [issue18958] Exception('No JSON object could be decoded') when parsing a valid JSON
report at bugs.python.org
Sat Oct 19 05:47:01 CEST 2013
Ezio Melotti added the comment:
I'm not sure this should be documented in json.load/loads, and I'm not sure people will look there once they get this exception.
The error is raised because the wrong codec is used (either by open() before passing the file object to json.load or by json.loads), so it's a user error rather than a problem with the json module. The error turns out to be particularly misleading because the decoding is successful even though it produces a wrong result, and the problem becomes apparent only once it reaches json.
ISTM that the documentation is already clear enough that json doesn't auto-detect encodings and uses UTF-8 by default, and that different encodings should be specified explicitly.
I think that a better and backward-compatible solution would be to detect the UTF-8 BOM and provide a better error message hinting at utf-8-sig.
Python tracker <report at bugs.python.org>
More information about the docs