On Aug 8, 2019, at 3:55 PM, Chris Angelico <firstname.lastname@example.org> wrote:
There are two broad suggestions that came out of that thread and
others, and I think it may be worth reopening them.
1) Should JSONEncoder (the class underlying json.dumps) natively
support decimal.Decimal, and if so, can it avoid importing that module
2) Should there be a protocol obj.__json__() to return a string
representation of an object for direct insertion into a JSON file?
I'm inclined towards the protocol, since there are protocols for
various other encoders (eg deepcopy, pickle), and it avoids the
problem of json importing decimal. It can also be implemented entirely
as a third-party patch, although you'd need to subclass Decimal to add
I proposed something similar about a year ago . I really like the idea
of a protocol for this. Especially since the other encoders already use
this approach. Should I reboot this approach? The implementation was
really simple .