alertmanager-bark-hook/utils/json_encoder.py

18 lines
503 B
Python
Raw Permalink Normal View History

2022-08-08 05:51:01 +00:00
from flask.json import JSONEncoder
import datetime
import decimal
class JSONEncoder(JSONEncoder):
def default(self, obj):
try:
if isinstance(obj, datetime.datetime):
return obj.strftime('%Y-%m-%d %H:%M:%S')
elif isinstance(obj, decimal.Decimal):
return float(obj)
iterable = iter(obj)
except TypeError:
pass
else:
return list(iterable)
return JSONEncoder.default(self, obj)