Antoine Pitrou writes:
Here is a use case where it may remove some pain from users'life: https://bugs.python.org/issue24313
The problem is that a protocol like __json__ doesn't help in deserializing, so you either can't use json.loads(), or more likely you'll need to have a post-parser to rebuild the objects. And it actually doesn't help as much as you'd hope in serializing, either, not for a decade or so, because most objects won't have a __json__ method. So every time somebody creates an object that they want to serialize, they'll have to subclass any imported class that doesn't have a __json__ method, and in the somewhat likely event they want to deserialize, they'll need to provide an ad hoc parser for that kind of object rather than using json.loads() (or hook it into the post-parser somehow). Robust programs will have to trap the inevitable AttributeErrors. And you can be sure that people will be adding __json__ methods to some of their application classes, so they'll start expecting __json__ methods on any object they put in such classes. Seems like a magnet for bug reports and RFEs to me. It's still true that just defining the protocol could allow users to just use json.dumps() for many common cases, which is clearly very convenient. I don't think it's worth the fragility, though. Steve