Last active
December 18, 2015 12:39
-
-
Save Flushot/5784832 to your computer and use it in GitHub Desktop.
Equivalent of json.dumps() but includes ISO-8601 date encodings of datetime and date data.
This file contains 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 | |
import datetime | |
from dateutil import tz | |
from naive_aware import isAware, makeAware, makeNaive | |
def jdumps(obj): | |
return json.dumps(obj, | |
default=lambda o: (makeAware(o) if isinstance(o, datetime.datetime) else o).isoformat() \ | |
if (isinstance(o, datetime.datetime) or isinstance(o, datetime.date)) else None, | |
sort_keys=True, | |
indent=4) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment