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

Multipass yajl.dumps() breaks with unicode #7

Closed indigoviolet closed 14 years ago

indigoviolet commented 14 years ago

Summary is that if you have a unicode string as a value in a dict, and for some reason you want to do dumps({key: dumps(value)}), and then retrieve value, it breaks with py-yajl and not with standard library json. Is this something you're able to fix?

See console session below:

In [9]: u Out[9]: u'f\xe9in'

In [10]: print u -------> print(u) féin

In [11]: out = json.dumps({'a': json.dumps(u)})

In [12]: out Out[12]: '{"a": "\"f\u00e9in\""}'

In [13]: json.loads((json.loads(out))['a']) Out[13]: u'f\xe9in'

In [14]: out = yajl.dumps({'a': yajl.dumps(u)})

In [15]: out Out[15]: '{"a":"\"f\xc3\xa9in\""}'

In [16]: yajl.loads((yajl.loads(out))['a'])

UnicodeEncodeError Traceback (most recent call last)

in () UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 2: ordinal not in range(128)
indigoviolet commented 14 years ago

Adding clearer console session

indigoviolet commented 14 years ago

Hey,

Do you have any idea when you're going to be able to get to this and #11?

Thanks!

indigoviolet commented 14 years ago

Argh. I closed this by mistake.

rtyler commented 14 years ago

I am pretty sure I resolved this in the latest commits, perhaps not.

FWIW you can join #yajl on Freenode if you have direct questions

rtyler commented 14 years ago

This should be resolved with the merging of SHA: 01cb3f10a3189100a91b6bdc2f5295f8f4782bfe