JSON

Marc Christiansen usenet at solar-empire.de
Thu Dec 6 20:05:41 EST 2007


Joshua Kugler <jkugler at bigfoot.com> wrote:
> belred at gmail.com wrote:
> 
>> i tried a couple python json libraries. i used simplejson on the
>> server and was using cjson on the client, but i ran into this issue.
>> i'm now using simplejson on both sides, but i'm still interested in
>> this issue.  did i do something wrong? is there a bug in one of the
>> libraries? or something i don't understand about the json spec?
>> 
>> 
>> i problem is the line where i call cjson.decode() below:
>> 
>>>>> import simplejson
>>>>> import cjson
>>>>>
>>>>> sj = simplejson.dumps('http://server.com')
>>>>> sj
>> '"http:\\/\\/server.com"'
>>>>> cj = cjson.encode('http://server.com')
>>>>> cj
>> '"http://server.com"'
>>>>> simplejson.loads(cj)
>> u'http://server.com'
>>>>> cjson.decode(cj)
>> 'http://server.com'
>>>>> simplejson.loads(sj)
>> u'http://server.com'
>>>>> cjson.decode(sj)
>> 'http:\\/\\/server.com'     # is this correct????
> 
> Known issue.  See:
> http://blog.extracheese.org/2007/07/when-json-isnt-json.html
> 
> Neither project has fixed it it seems.  Not sure which is actually
> the "correct" way to do it, but it would be nice if they would agree.

Since both Opera and SpiderMonkey give http://server.com as result for
eval('"http:\\/\\/server.com"'), I'd say cjson gets it wrong (If by
nothing else than majority rule ;). That is unless I'm wrong that in
javascript something like eval(JSON_repr_of_s) == s should be true.

Marc



More information about the Python-list mailing list