You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
the actual updated library 1.2.1 throws exception when encoding { 1 : 'a' }
while the older czjson library 1.0.8 was fixed to allow encode of { 1 : 'a' }
thank you
The text was updated successfully, but these errors were encountered:
This is not a bug. The JSON standard only allows object (dictionary) keys to be strings and cjson clearly tells you that in the error message:
In [2]: cjson.encode({1: 'a'})
---------------------------------------------------------------------------
EncodeError Traceback (most recent call last)
<ipython-input-2-6990413e0aea> in <module>()
----> 1 cjson.encode({1: 'a'})
EncodeError: JSON encodable dictionaries must have string/unicode keys
In this regard 1.0.8 was in error and it was fixed.
Other json implementations will automatically convert integers to strings, but that means that encoding and then decoding a dictionary like that will result in a different dictionary:
In [3]: json.loads(json.dumps({1: 'a'}))
Out[3]: {u'1': u'a'}
cjson refuses to make assumptions about your intentions and simply signals the error and expects you to fix it by providing data that can be encoded in JSON without errors.
the actual updated library 1.2.1 throws exception when encoding { 1 : 'a' }
while the older czjson library 1.0.8 was fixed to allow encode of { 1 : 'a' }
thank you
The text was updated successfully, but these errors were encountered: