« Return to Thread: JSON parser grammar

RE: JSON parser grammar

by Allen Wirfs-Brock-2 :: Rate this Message:

Reply to Author | View in Thread

>-----Original Message-----
>From: Robert Sayre [mailto:sayrer@...]
>Sent: Tuesday, June 02, 2009 10:33 PM
>To: Allen Wirfs-Brock
>Cc: Oliver Hunt; Mark S.Miller; Rob Sayre; es-discuss@...
>Subject: Re: JSON parser grammar
>
>On Wed, Jun 3, 2009 at 1:27 AM, Allen Wirfs-Brock
><Allen.Wirfs-Brock@...> wrote:
>>
>> The intent was for the ES5 JSON grammar to exactly match the JSON RFC
>grammar.  If you think it is different, then you may have found a bug so
>let's make sure...
>
>It definitely doesn't match, on purpose. For example, the RFC requires
>JSON strings to represent objects (or arrays) at the root, no
>primitives allowed.

You're right, we did intentionally allow top level primitives.

>
>>
>> Examples, please? The intent is that applying JSON.parse to a string
>containing a valid JSON form should produce an equivalent set of objects
>on all conforming ES5 implementation.
>
>JSON.parse("[010]")
>
>should be an error, per spec. Nobody follows the spec though...
>

As I read them neither the RFC or the current ES5 JSON grammar recognize "[010]" as a valid JSON form, so according to the ES5 spec. a syntax error should be thrown.  If we really want all implementation to accept "010" as a JSONNumber then we should specify it as such.  Of course we have to define what it means (decimal, octal??).

My inclination would be to require ES5 implementation to exactly conform the whatever JSON grammar we provide and to throw syntax errors if the input doesn't exactly conform to the grammar. (in other say that the section 16 extension allowance doesn't apply to JSON.parse.  If an implementation wants to support JSON syntax extensions it could always do so by providing a JSON.parseExtended function (or whatever they want to call it) that uses an implementation defined grammar.

Allen
_______________________________________________
es-discuss mailing list
es-discuss@...
https://mail.mozilla.org/listinfo/es-discuss

 « Return to Thread: JSON parser grammar