On Jun 30, 1:39 pm, Reinier Zwitserloot <
reini...@gmail.com> wrote:
> Therefore, in JSON, there are also only doubles. HOWEVER, if you pass
> an int into JSON, then it gets turned into a double, but, all ints are
> perfectly representable in doubles, and therefore, if you then receive
> the double, it'll be the exact same int, even without rounding.
Actually, in JSON there are only "numbers", not integers or doubles.
Unfortunately, because the JSON spec doesn't specify any bounds on the
size of "number", there's no guarantee that all your ints will fit
into whatever datatype your parser decides to use. The relevant part
of the spec:
"A number contains an integer component that
may be prefixed with an optional minus sign, which may be followed
by
a fraction part and/or an exponent part."
and the grammar breaks down into:
number = [ minus ] %x30 / (%x31-39 *DIGIT) [ frac ] [ exp ]
Which unfortunately means that your JSON writer is possibly perfectly
capable of encoding integers that are too large to fit into whatever
data type is used to decompose a "number" on the other side (a problem
you are doubly likely to encounter if your client and server are
written in different languages).
The spec states:
"An implementation may set limits on the range of numbers."
But it does not define any limits (even recommended), so you are left
to the mercy of your parsers.
--
Nick