[pypy-issue] [issue1460] json loads with object_pair_hook

Matthew Schinckel tracker at bugs.pypy.org
Sat Apr 20 00:30:22 CEST 2013


New submission from Matthew Schinckel <matt at schinckel.net>:

There is a subtle difference in pypy's handling of json.loads, with respect to 
object_pairs_hook, when an empty object is parsed.

Code speaks loud:

Python 2.7.2:

$python
Python 2.7.2 (default, Oct 11 2012, 20:14:37) 
[GCC 4.2.1 Compatible Apple Clang 4.0 (tags/Apple/clang-418.0.60)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import json
>>> from collections import OrderedDict
>>> 
>>> json.loads('{}')
{}
>>> json.loads('{}', object_pairs_hook=OrderedDict)
OrderedDict()
>>> json.loads('{"foo":2}', object_pairs_hook=OrderedDict)
OrderedDict([(u'foo', 2)])



PyPy 1.9.0

$ pypy
Python 2.7.2 (341e1e3821ff, Jun 07 2012, 15:42:54)
[PyPy 1.9.0 with GCC 4.2.1] on darwin
Type "help", "copyright", "credits" or "license" for more information.
And now for something completely different: ``snow, snow''
>>>> import json
>>>> from collections import OrderedDict
>>>> 
>>>> json.loads('{}')
{}
>>>> json.loads('{}', object_pairs_hook=OrderedDict)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/Cellar/pypy/1.9/lib-python/2.7/json/__init__.py", line 339, in 
loads
    return cls(encoding=encoding, **kw).decode(s)
  File "/usr/local/Cellar/pypy/1.9/lib-python/2.7/json/decoder.py", line 369, in 
decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 1 - line 1 column 2 (char 1 - 2)
>>>> json.loads('{"foo":2}', object_pairs_hook=OrderedDict)
OrderedDict([(u'foo', 2)])
>>>>

----------
messages: 5603
nosy: pypy-issue, schinckel
priority: bug
release: 1.9
status: unread
title: json loads with object_pair_hook

________________________________________
PyPy bug tracker <tracker at bugs.pypy.org>
<https://bugs.pypy.org/issue1460>
________________________________________


More information about the pypy-issue mailing list