Chris Angelico wrote:
2) Should there be a protocol obj.__json__() to return a string representation of an object for direct insertion into a JSON file?
However, this is a much broader topic, and if you want to push for that, I would recommend starting a new thread. As Andrew pointed out, trying to get bit-for-bit identical JSON representations out of different encoders is usually a bad idea.
I am not sure I have ever asked for bit-for-bit identical JSON representation. I have always only mentioned `decimal.Decimal` and the lack of proper way to encode it (while having the proper way of decoding it), and if you read the subject of the OP it is asking for "raw output" (in the encoder, nothing about underlying representation) which if I understand your two options basically corresponds to the second one and is probably addressed elsewhere far more thoroughly. If my understanding is right, I would be also very much in favor of this approach.