JSON parser grammar

Oliver Hunt oliver at apple.com
Fri Jul 3 17:29:24 PDT 2009

On Jul 3, 2009, at 3:41 PM, Hallvord R. M. Steen wrote:

> On Wed, 03 Jun 2009 21:42:46 +0200, Allen Wirfs-Brock <Allen.Wirfs-Brock at microsoft.com 
> > wrote:
>> 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.
> This may be a stupid question, but..
> How can you allow "strings" as top level JSON text and keep the  
> 15.12.2 step 2 requirement that JSON.parse() must throw if the input  
> isn't valid JSON source text? In other words, how is an  
> implementation supposed to know if I'm passing in a string of random  
> content that should be "parsed" into a string or a malformed piece  
> of JSON that should cause an exception?

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.


More information about the es-discuss mailing list