Skip to content

Instantly share code, notes, and snippets.

@beatak
Last active May 23, 2018 18:24
Show Gist options
  • Save beatak/a9ff59ab13c1cc0c23dde56df3be8b3f to your computer and use it in GitHub Desktop.
Save beatak/a9ff59ab13c1cc0c23dde56df3be8b3f to your computer and use it in GitHub Desktop.
import json
from datetime import date, datetime, timedelta
def json_serial(obj):
if isinstance(obj, (datetime, date)):
return obj.isoformat()
elif isinstance(obj, (timedelta)):
return obj.total_seconds()
raise TypeError ("Type %s not serializable" % type(obj))
logging.info( json.dumps(response, indent=2, default=json_serial) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment