New submission from Haoyu SUN <raptor...@gmail.com>:
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}' ---------- components: Library (Lib) messages: 368942 nosy: Haoyu SUN priority: normal severity: normal status: open title: json.dumps() should encode float number NaN to null type: behavior versions: Python 3.6 _______________________________________ 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