JSON parser grammar
Allen Wirfs-Brock
Allen.Wirfs-Brock at microsoft.com
Mon Jul 6 15:09:57 PDT 2009
IE8 does correctly process:
JSON.parse("\"foo\"")
I just tried it and it worked fine. There are a few discrepancies between the IE8 JSON implementation and the current ES5 draft. See http://blogs.msdn.com/jscript/archive/2009/06/23/native-json-support-in-ie8-and-tracking-the-ecmascript-fifth-edition-draft-specification.aspx for details.
Allen
>-----Original Message-----
>From: Hallvord R. M. Steen [mailto:hallvord at opera.com]
>Sent: Saturday, July 04, 2009 4:49 AM
>To: Oliver Hunt
>Cc: Allen Wirfs-Brock; Rob Sayre; Mark S.Miller; es-discuss at mozilla.org;
>Douglas Crockford; Robert Sayre
>Subject: Re: JSON parser grammar
>
>>>> a) Allow strings, numbers, Booleans, and null in addition to objects
>>>> and
>>>> 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
>> literal.
>
>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
>
>JSONNumber ::
>-opt DecimalIntegerLiteral JSONFraction opt ExponentPart opt
>
>
>JSONFraction ::
>. DecimalDigits
>
>This apparently makes numbers like "1." illegal? Should this really
>throw:
>
>JSON.parse('[1.]') ?
>
>And what about
>JSON.parse('[1.e10]') ?
>
>Both are of course allowed in normal JavaScript source text.
>
>--
>Hallvord R. M. Steen, Core Tester, Opera Software
>http://www.opera.com http://my.opera.com/hallvors/
More information about the es-discuss
mailing list