Introduce a __json__ magic method

As I wrote in the past thread, __json__ solves only serialization. It can not solve deserialization of custom object. So I prefer two stage approach like pydantic.

If we really need to add the method, I think it should be simplejson compatible.

https://simplejson.readthedocs.io/en/latest/#simplejson.dumps

If for_json is true (not the default), objects with a for_json() method will use the return value of that method for encoding as JSON instead of the object.

3 Likes