INNER CODE UNIT · Python
encoder
chaostoolkit/chaostoolkit · chaostoolkit/__init__.py:14
def encoder(o: object) -> str:
"""
Perform some additional encoding for types JSON doesn't support natively.
We don't try to respect any ECMA specification here as we want to retain
as much information as we can.
"""
if isinstance(o, (date, datetime)):
# we do not meddle with the timezone and assume the date was
# stored with the right information of timezone as +-HH:MM
return o.isoformat()
elif isinstance(o, (decimal.Decimal, uuid.UUID)):
return str(o)
raise TypeError(f"Object of type '{type(o)}' is not JSON serializable")