[Haskell-cafe] JSON library suggestions?

Alvaro Gutierrez radical at google.com
Tue Apr 24 23:51:56 CEST 2012


JSON numbers are not equivalent to JavaScript/ECMAScript numbers, even if
they are nominally related; the key differences are that in JSON, numeric
literals:

(a) can have any non-zero number of digits, effectively making JSON numbers
both unbounded and arbitrarily precise (though actual infinities cannot be
represented); and
(b) cannot represent values that are not composed of digits, like NaN.

For that reason, most standard (fixed size/binary) numeric types like
double are a poor choice to contain numeric values specified in JSON; in
particular, the mismatch means that conversion can be lossy in both
directions.

Hope that helps!

Alvaro


On Tue, Apr 24, 2012 at 5:19 PM, Jeremy Shaw <jeremy at n-heptane.com> wrote:

> Hello,
>
> I could be wrong, but I think the only real numeric type in javascript
> is 'Number' which is a floating point number? Which is why Aeson and
> others insist on converting everything to a Double or other Rational
> number?
>
> - jeremy
>
> On Tue, Apr 24, 2012 at 3:46 PM, Jeff Shaw <shawjef3 at msu.edu> wrote:
> > Hello,
> > Up until now I've been using Aeson, but I've found that its number type
> > isn't going to work for me. I need to use decimal numbers while avoiding
> > conversions from and to Double, which Aeson doesn't allow. There are
> quite a
> > few more JSON libraries for Haskell, which all appear to use Rational for
> > numbers, so I'm wondering if anyone can recommend one.
> >
> > Thanks,
> > Jeff
> >
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120424/84720d6f/attachment.htm>


More information about the Haskell-Cafe mailing list