Mark Dickinson <dicki...@gmail.com> added the comment:

For the record, some helpful resources:

ECMA-404 (the ECMA standardization of JSON): 
http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-404.pdf

RFC 8259 (current RFC for JSON): https://tools.ietf.org/html/rfc7159. (I 
mistakenly referred to RFC 7159 in a previous comment, but that's obsoleted by 
RFC 8259; however, none of the language around infinities and nans has changed, 
and none of the current errata to RFC 8259 have any impact on infinity or nan 
encoding.)

This Stack Overflow question and its answers contain some interesting 
discussion and links: 
https://stackoverflow.com/questions/1423081/json-left-out-infinity-and-nan-json-status-in-ecmascript
 

Essentially, there's no good answer here: standard JSON simply can't encode 
infinities and NaNs. Absent a fix for the standard itself, both Python and 
ECMAScript end up papering over that fact. Unfortunately from an 
interoperability point of view, they do so in different ways - Python 
effectively extends the JSON spec in such a way that it produces invalid JSON 
by default; ECMAScript converts all of Infinity, -Infinity, NaN and null to the 
exact same JSON string, producing valid JSON but losing the ability to restore 
the original values from their JSON representations.

FWIW, Python's solution to this problem is (whether by accident or design I'm 
not sure) forward-looking in the sense that it's compatible with JSON 5: 
https://spec.json5.org

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue40633>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to