On Tue, Jun 16, 2020, 8:42 PM Steven D'Aprano <steve@pearwood.info> wrote:
Please forgive the stupid question, but given that the JSON standard is so obviously broken (being unable to serialise valid values from a supported type, what on earth were they thinking???), wouldn't all this time and energy be better aimed at fixing the standard rather than making Python's JSON encoder broken by default?

I do not support changing the default in the Python library. 

However, I do want to note that JSON is not "broken." The data that gets represented in JSON may have the type "Number" (RFC 7159). That is, there is no concept of IEEE-754 floating point, or integer, or Decimal, etc. There is simply the type "Number" that a particular programming language may approximate in one of its available types.

The type Number has no specific semantics, only a grammar for what sequences of characters qualify. There is a large intersection with the things representable in IEEE-754, but it's neither a subset not superset of that. From the RFC:

A JSON number such as 1E400 or 3.141592653589793238462643383279
may indicate potential interoperability problems, since it 
suggests that the software that created it expects receiving 
software to have greater capabilities for numeric magnitude 
and precision than is widely available.


On the other side, strings like -inf, Infinity, or NaN are not matched by the grammar.