TDAgentTools / tdagent /utils /json_utils.py
Josep Pon Farreny
chore: Multiple fixes and whois tool
fffd163
raw
history blame
434 Bytes
import datetime
import json
class TDAgentJsonEncoder(json.JSONEncoder):
"""Extend JSON encoder with known types."""
def default(self, o: object) -> object: # noqa: D102
if isinstance(o, datetime.datetime):
return {"__type__": "datetime", "value": o.isoformat()}
if isinstance(o, datetime.date):
return {"__type__": "date", "value": o.isoformat()}
return super().default(o)