OData Decimal and JSON

A few days ago I came upon a question about how decimal values are encoded in JSON payload in an OData response. The value was in quotes rather than as a numeric literal, so a script running in a browser found a string where the developer thought a number would be found.

I confirmed that this is indeed by design, and in fact you can verify this in the corresponding OData Protocol page. The reason for this is that JSON is used to interop across different kinds of systems, but while www.json.org describes what a number looks like, it doesn’t require implementations to support any particular representations in terms of how large / small / precise the values can be.

To make sure that systems can round-trip data – read it and write it back without unintentional modifications – we were very careful about only using a numeric literal form for very simple common cases (16-bit and 32-bit signed values, to be precise).


Comments (0)

Skip to main content