Subject: | inf and nan handling |
Perl's JSON deals with +-inf and nan by emitting invalid json. This is documented: "these cannot be represented in JSON, and it is an error to pass those in." This is not so user-friendly: the json standard says you should use null. There is no option to emit null.
The Python JSON module defaults to throwing an exception, or optionally emits valid Javascript names for these guys. That is against the json standard, but hey, it's optional.
http://docs.python.org/2/library/json.html
Show quoted text
> If allow_nan is False (default: True), then it will be a ValueError to
> serialize out of range float values (nan, inf, -inf) in strict
> compliance of the JSON specification, instead of using the JavaScript
> equivalents (NaN, Infinity, -Infinity).
See also:
http://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
for a long and fruitless discussion.
Suggestion:
At the least, it would be nice for perl JSON to have an option where it emits null for these values -- conforming to the standard. It would also be nice to have an option to throw an exception when nan/inf are encoutered.
It might also be nice to have an option to do it the python (Nan/Infinity) way, and to accept the python way.
Thanks for the JSON module, we used the JSON::XS module as the basis of our serializer/deserializer, and have a few petabytes of data stored with it!