v = json.loads("{'test':'test'}")

Matt Nordhoff mnordhoff at mattnordhoff.com
Sun Jan 25 21:38:48 EST 2009


Matt Nordhoff wrote:
> gert wrote:
>> On Jan 25, 11:16 pm, Дамјан Георгиевски <gdam... at gmail.com> wrote:
>>>> raise ValueError(errmsg("Expecting property name", s, end))
>>>> http://docs.python.org/library/json.html
>>>> What am I doing wrong ?
>>> try this
>>> v = json.loads('{"test":"test"}')
>>>
>>> JSON doesn't support single quotes, only double quotes.
>> the funny part is when you print(v) you get
>> {'test': 'test'}
>>
>> Single quotes works in every browser that support json so i
>> recommended python should support it too, besides it looks much
>> cleaner
>> {'test': 'test'}
>> {"test": "test"}
>>
>> It can not be that hard to support both notation can it ?
> 
> There's a difference between JavaScript source code and JSON. AFAICT
> from the source [1], Mozilla's JSON parser doesn't accept single quotes.
> 
> [1] <http://mxr.mozilla.org/mozilla-central/source/js/src/json.cpp>

By the way, I forgot to add, according to the ECMA-262 standard (page
18, section 7.8.4) [1], ECMAScript string literals can use either double
or single quotes, so that's not a browser-specific extension.

[1]
<http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf>
(<http://xrl.us/bedr3c>)
-- 



More information about the Python-list mailing list