4.5.3: Type inference for numeric values doesn't work with JSON.parse()

    • Type: Bug
    • Resolution: Fixed
    • Priority: Major
    • V4.0_ERRATA01
    • Affects Version/s: V4.0_OS
    • Component/s: JSON Format
    • None
    • Environment:

      [Proposed][Applied]

    • Hide

      Change text to

      • Numeric values have a first-class representation in JSON but are not further distinguished, so they include an odata.type annotation unless their type is Double.

      Show
      Change text to • Numeric values have a first-class representation in JSON but are not further distinguished, so they include an odata.type annotation unless their type is Double.

      Section 4.5.3 says

      Numeric values have a first-class representation in JSON and do not need any additional annotations. If the value of a property is represented as a number without a dot (.), e or E embedded, the type should be interpreted as an integer value, otherwise as a decimal, double, or single value.

      Unfortunately this type inference does not work for clients using generic JSON parsers, e.g. JSON.parse() in JavaScript. The lines

      var payload = '

      { "x" : 1.2e4 }

      ';
      var parsed = JSON.parse(payload);
      console.log(parsed.x);

      will result in 12000.

            Assignee:
            handl
            Reporter:
            handl
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: