Last active
May 23, 2018 18:24
-
-
Save beatak/a9ff59ab13c1cc0c23dde56df3be8b3f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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