Skip to content

Instantly share code, notes, and snippets.

@darrellsilver
Created April 3, 2014 19:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darrellsilver/9961183 to your computer and use it in GitHub Desktop.
Save darrellsilver/9961183 to your computer and use it in GitHub Desktop.
import json
import datetime
class DeepEncoder(json.JSONEncoder):
def default(self, obj):
if type(obj) in (datetime.datetime, datetime.date):
return obj.isoformat()
try:
return super(DeepEncoder, self).default(obj)
except TypeError, te:
return obj.__dict__
res = json.dumps(res_normalized, cls=DeepEncoder, **kwargs)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment