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

J. Cliff Dyer jcd at sdf.lonestar.org
Tue Jan 27 11:37:35 EST 2009


On Sun, 2009-01-25 at 14:28 -0800, 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 ?

It's not that hard, but it does add a noticeable level of complexity to
the process.  In JSON, you simply tell the parser, "if you see a
double-quote character, we're now parsing a string.  When you see
another (unescaped) double-quote character, the string is done.

The equivalent version for your extended JSON would say, "if you see a
quote character of either kind, we're parsing a string.  When you see
another (unescaped) quote character of either kind, the string is done."
But that doesn't work, because it would allow {'test": "test'}.  So the
parser has to remember which quote character is being used, and require
those characters to be escaped, and not the other (but then does "te
\'st" render as r"te'st" or r"te\'st"?) and only close the string when
the appropriate quote is found.  

Not an impossible task, but certainly more complex than the current
parsing requirements for JSON.

Cheers,
Cliff





More information about the Python-list mailing list