Skip to content

Instantly share code, notes, and snippets.

@doug
Created September 5, 2012 22:41
Show Gist options
  • Save doug/3646668 to your computer and use it in GitHub Desktop.
Save doug/3646668 to your computer and use it in GitHub Desktop.
dump json with extras
import json
import datetime
import time
def json_extras(obj):
if hasattr(obj, 'utctimetuple'):
ms = time.mktime(obj.utctimetuple()) * 1000
ms += getattr(obj, 'microseconds', 0) / 1000
return int(ms)
return None
json.dumps({'time':datetime.datetime.now()}, default=json_extras)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment