Uploaded image for project: 'OASIS Open Data Protocol (OData) TC'
  1. OASIS Open Data Protocol (OData) TC
  2. ODATA-707

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

    XMLWordPrintable

    Details

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

      [Proposed][Applied]

    • Proposal:
      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.

      Description

      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.

        Attachments

          Activity

            People

            • Assignee:
              handl Ralf Handl
              Reporter:
              handl Ralf Handl
            • Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: