A multipurpose python flask API server and administration SPA
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

18 lines
444 B

  1. from datetime import date
  2. from typing import Any
  3. import rfc3339
  4. from flask.json import JSONEncoder
  5. class CustomJSONEncoder(JSONEncoder):
  6. def default(self, obj: Any) -> Any:
  7. try:
  8. if isinstance(obj, date):
  9. return rfc3339.format(obj)
  10. iterable = iter(obj)
  11. except TypeError:
  12. pass
  13. else:
  14. return list(iterable)
  15. return JSONEncoder.default(self, obj)