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

Round-tripping integers and floats doesn't work with yajl #15

Closed indigoviolet closed 14 years ago

indigoviolet commented 14 years ago
Fri 9  8:44PM> python
Python 2.6 (r26:66714, Apr  2 2009, 13:18:58) 
[GCC 4.1.2 20071124 (Red Hat 4.1.2-42)] on linux2
Type "help", "copyright", "credits" or "license" for more information.

>>> import yajl
>>> import json
>>> yajl.dumps(1)
'1'
>>> yajl.loads('1')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: eof was met before the parse could complete
>>> json.dumps(1)
'1'
>>> json.loads('1')
1
>>> yajl.dumps(1.05)
'1.05'
>>> yajl.loads('1.05')
Traceback (most recent call last):
  File "", line 1, in 
ValueError: eof was met before the parse could complete
>>> json.dumps(1.05)
'1.05'
>>> json.loads('1.05')
1.05
>>> 

rtyler commented 14 years ago

This is actually correct behavior, the json module is incorrect here. Objects being passed in as JSON should be either objects (dicts) or arrays (lists).

indigoviolet commented 14 years ago

Ok, I didn't realize that. Thanks.