scolby33 / OCSPdash

A dashboard for the status of the top certificate authorities' OCSP responders.
MIT License
1 stars 0 forks source link

JSON Serialization of the payload #7

Closed scolby33 closed 7 years ago

scolby33 commented 7 years ago

See here. How do you do this recursively on objects?

cthoyt commented 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
scolby33 commented 7 years ago

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.

cthoyt commented 7 years ago

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

scolby33 commented 7 years ago

I did it in __init__.py because I'm bad like that.