[issue17368] Python version of JSON decoder does not work with object_pairs_hook
Aki
report at bugs.python.org
Wed Mar 6 17:31:45 CET 2013
New submission from Aki:
Specifying any object_pairs_hook makes JSON decoding break when JSONObject from json/decoder.py is used.
Can be emulated easily by setting c_make_scanner = None at json/scanner.py
Example script:
**
import json
test = '{"key": "value", "empty": {}}'
def hook(pairs):
return dict(pairs)
print(json.loads(test, object_pairs_hook=hook))
**
This test will fail because the return statement on line 166 in http://hg.python.org/cpython/file/cfc777407b03/Lib/json/decoder.py lacks "+ 1" even though the statement on line 170 has it. Basically, any empty JSON object will cause "ValueError: Extra data: [...]".
----------
components: Library (Lib)
messages: 183600
nosy: Kuukunen
priority: normal
severity: normal
status: open
title: Python version of JSON decoder does not work with object_pairs_hook
versions: Python 2.7, Python 3.1, Python 3.2, Python 3.3, Python 3.4, Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17368>
_______________________________________
More information about the Python-bugs-list
mailing list