This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author Haoyu SUN
Recipients Haoyu SUN
Date 2020-05-15.13:42:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1589550124.35.0.830023884715.issue40633@roundup.psfhosted.org>
In-reply-to
Content
Float numbers in Python can have 3 special number: nan, inf, -inf, which are encoded by json module as "NaN", "Infinity", "-Infinity". These representations are not compatible with JSON specifications RFC7159:
https://tools.ietf.org/html/rfc7159.html#page-6

These values are not correctly parsed by most JavaScript JSON encoders.

It is better to encode "NaN" to "null" which is a valid JSON keyword representing "Not a Number".

Here is an example how json.dumps() encodes NaN to NaN in JSON:
Python 3.6.9 (default, Apr 18 2020, 01:56:04)
[GCC 8.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> dct = {'a': None, 'b' : float('nan')}
>>> dct
{'a': None, 'b': nan}
>>> import json
>>> json.dumps(dct)
'{"a": null, "b": NaN}'
History
Date User Action Args
2020-05-15 13:42:04Haoyu SUNsetrecipients: + Haoyu SUN
2020-05-15 13:42:04Haoyu SUNsetmessageid: <1589550124.35.0.830023884715.issue40633@roundup.psfhosted.org>
2020-05-15 13:42:04Haoyu SUNlinkissue40633 messages
2020-05-15 13:42:04Haoyu SUNcreate