Message368942
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}' |
|
Date |
User |
Action |
Args |
2020-05-15 13:42:04 | Haoyu SUN | set | recipients:
+ Haoyu SUN |
2020-05-15 13:42:04 | Haoyu SUN | set | messageid: <1589550124.35.0.830023884715.issue40633@roundup.psfhosted.org> |
2020-05-15 13:42:04 | Haoyu SUN | link | issue40633 messages |
2020-05-15 13:42:04 | Haoyu SUN | create | |
|