JSON parser grammar

Oliver Hunt oliver at apple.com
Tue Jun 2 19:06:56 PDT 2009


So i've been looking at the JSON object grammar and have been talking  
to brendan and i'm getting somewhat conflicting information.

The grammars on json.org and in the ES5 spec both prohibit leading 0's  
on any number, but the various implementations disagree with this.

json2.js (from json.org), ie8, and chrome all support the standard ES  
octal literal lexer -- eg. JSON.parse("[010]")[0] === 8

SpiderMonkey allows a leading 0 but still interprets it as a decimal  
value -- eg. JSON.parse("[010]")[0] === 10

It seems to me that the spec needs to be corrected to specify what the  
behaviour actually is, rather than what we wish it could be.

--Oliver



More information about the es-discuss mailing list