JSON parser grammar

Mark S. Miller erights at google.com
Thu Jun 4 07:42:34 PDT 2009

On Thu, Jun 4, 2009 at 1:19 AM, Christian Plesner Hansen
<christian.plesner.hansen at gmail.com> wrote:
> It's unclear to me from reading this thread if any other browsers
> actually implement JSON correctly according to ES5.

More, it seems clear from reading this thread that none do.

> If none do, how
> sure are we that these changes won't break people's programs?

"Sure" is never an option ;). Our relative confidence comes from our
knowledge of the behavior of various popular json emitters. In
particular, we know of none that emit octal.

> As for octal literals I agree that they're not a good idea.  However,
> adding new special cases to avoid them is a cure worse than the
> disease.  It adds to the complexity of the language in an area that is
> already dangerously complex.

Since octal syntax will currently be interpreted as decimal on some
browsers and octal on others, even by json.js (since it delegates to
eval), there is no safe way to allow this syntax. By allowing them,
one's JSON.parse is no longer validating. It will not complain about
data that will be interpreted differently by different browsers.

Recall that we felt we needed to add JSON support to the spec because
JS library code cannot provide parsers that are simultaneously fast,
safe, and validating. If all you want is safe and fast, json_sans_eval
is a fine solution that works on existing browsers.


More information about the es-discuss mailing list