rtyler / py-yajl

py-yajl provides Python bindings for the Yajl JSON encoder/decoder library
http://rtyler.github.com/py-yajl
74 stars 18 forks source link

0.3.4 breaks dict serialization #12

Closed indigoviolet closed 14 years ago

indigoviolet commented 14 years ago

In [2]: yajl.__file__
Out[2]: '.python_eggs/yajl-0.3.4-py2.6-linux-x86_64.egg-tmp/yajl.so'

In [3]: yajl.dumps({'a': 'b', 'c': 'd'})
Out[3]: '{"a":"b","c":"d"}'

In [4]: yajl.dumps({u'a': u'b', u'c': u'd'}) 
Out[4]: '{"a":"b"}'

In [5]: import json
In [6]: json.dumps({u'a': u'b', u'c': u'd'})                                                                                                           
Out[6]: '{"a": "b", "c": "d"}'

rtyler commented 14 years ago

Following up on this issue, here's what's going on.

In 0.3.4 I've added a "hack" which does the appropriate escaping of unicode objects to ascii-representations (i.e. \u00e9). In order to circumvent some additional escaping by yajl_gen_string() I was using yajl_gen_number() which does a raw print to the stream.

Turns out there's a safe-guard in yajl_gen_number() which tries to prevent using numbers as keys in a dict which causes an error to be returned on the second key-value pair that gets ignored in py-yajl (it's a bug in yajl that it wasn't caught on the first pair)

rtyler commented 14 years ago

SHA: 85f3aa53e030f7a2fc51b41db580431d98948990