On Sun, Aug 11, 2019, at 20:42, Chris Angelico wrote:
class float: def __json__(self): if math.isfinite(self): return str(self) return "null"
Er, to be clear, the current JSON decoder returns 'Infinity', '-Infinity', or 'NaN', which are invalid JSON, not null. This behavior (vs raising an exception) is governed by a flag. I'm mainly bringing this up to point out that the concerns about a raw protocol being able to generate invalid JSON seem somewhat overblown and that "people should be able to generate invalid JSON if they want to" is not without precedent.