javascriptjqueryjsonvalidationjsonlint

Floating point zero (0000000000000000E+00) in JSON not parsed in jQuery (Windows) / JSONLint


I have a problem with a piece of JSON containing a float number of 0000000000000000E+00 (essentially zero). Consider, for example:

{
    "a": 3199999999999999E+01,
    "b": 0000000000000000E+00,
    "c": 0,
    "d": 5
}

The zero floating point number gives an error under the following circumstances:

Changing the zero floating point number to any non-zero value gives no hassles.

Look also at the following JSFiddle: http://jsfiddle.net/Gr6fq/. When I run this in Linux, it works. On Windows, it gives an error.


Solution

  • It looks like the Javascript parser interprets the leftmost leading zero as the octal modifier, and proceeds to parse the current token as an octal number. It then chokes on the E token it encounters afterwards.

    Using Firefox 5.0's console:

    0E+00   // Okay, parsed as 0.
    00E+00  // Syntax error, identifier starts immediately after numeric literal.