[eeps] JSON

Alisdair Sullivan alisdairsullivan@REDACTED
Tue Jul 5 03:39:44 CEST 2011


On 2011-07-04, at 5:09 PM, Richard O'Keefe wrote:

> You cannot represent JSON numbers as strings if you want to claim "fidelity".
> 
>>>> json.loads('1.2e500')
> inf
> 
> The problem here is that we can't do that, because (at least in R14B), Erlang flatly
> refuses to treat inf as a number.

You cannot represent Javascript numbers as strings if you want to claim "fidelity". You CAN represent JSON numbers as strings. If Erlang had a decimal number type, would you insist JSON numbers still be represented as iee754 doubles? What if Erlang moves to extended precision floats? Should we not use those? JSON isn't Javascript, what Javascript is capable of is irrelevant.

The more I think about it, the more I think floats should be avoided unless explicitly requested by the user. Using floats makes JSON unsuitable for any sort of financial data interchange. That alone should be enough to bring pause to the notion that we should just do what Javascript does.

Perhaps a compromise would be to represent JSON numbers internally as a list of unicode codepoints (all valid JSON numbers formatted in this way are also valid Erlang strings) and allow the user to provide a function that formats that string in whatever manner they choose at parse time. A default function could be provided that converts everything to a float or follows the recommendations of eep0018.





More information about the eeps mailing list