Closed scolby33 closed 7 years ago
Monkey fucking patch the json module
from json import JSONEncoder
def _default(self, obj):
return getattr(obj.__class__, "to_json", _default.default)(obj)
_default.default = JSONEncoder().default # Save unmodified default.
JSONEncoder.default = _default # replacement
Why doesn't it have like __to_json__
that people can just implement on all their objects? That would have been the smart thing to do.
Yeah so jupyter looks for these magic dunder methods... It's also possible that we could make a custom decoder class and tell jsonify
to use it... but i think monkey patching is probably fine
I did it in __init__.py
because I'm bad like that.
See here. How do you do this recursively on objects?