isagalaev / ijson

Iterative JSON parser with Pythonic interface
http://pypi.python.org/pypi/ijson/
Other
615 stars 134 forks source link

unescape map keys #39

Closed danielvarga closed 9 years ago

danielvarga commented 9 years ago

This test shows that the python backend does not unescape the keys of a dict. I assume it should. The pull request fixes this. BTW the yajl backend returns str instead of unicode keys, which is probably might be a problem on its own.

import StringIO
import sys

assert sys.argv[1] in ('c', 'p')
cBackend = sys.argv[1]=='c'
if cBackend:
    import ijson.backends.yajl as ijson
else:
    import ijson

js = '[ {"a\\/b": "c\\/d"} ]'
print js
f = StringIO.StringIO(js)
for d in ijson.items(f, 'item'):
    print d

Output:

> python test.py p
[ {"a\/b": "c\/d"} ]
{u'a\\/b': u'c/d'}

> python test.py c
[ {"a\/b": "c\/d"} ]
{'a/b': u'c/d'}
isagalaev commented 9 years ago

Merged. Thanks!