JSON parser grammar
Hallvord R. M. Steen
hallvord at opera.com
Sat Jul 4 04:49:01 PDT 2009
>>> a) Allow strings, numbers, Booleans, and null in addition to objects
>>> arrays as top level JSON text.
>>> The ES5 spec. already has this although it isn't in the RFC. I haven't
>>> heard any suggestions that we remove it.
>> How can you allow "strings" as top level JSON text?
> A piece of text is either a string literal or it is not -- i suspect
> you're confusing JSON.parse("foo") where you are passing a string
> containing the characters f,o and o with JSON.parse("\"foo\"") in which
> the string contains the characters ",f,o,o and " -- eg. a string
Indeed I was, particularly since IE8's implementation doesn't seem to understand this string-inside-string feature yet so when I tried this earlier I remained confused :-p. Thanks for clarifying.
Another question: The JSON grammar says
-opt DecimalIntegerLiteral JSONFraction opt ExponentPart opt
This apparently makes numbers like "1." illegal? Should this really throw:
And what about
Hallvord R. M. Steen, Core Tester, Opera Software
More information about the es-discuss