Skip to content

Instantly share code, notes, and snippets.

@quezo
Created May 4, 2012 21:54
Show Gist options
  • Save quezo/2597979 to your computer and use it in GitHub Desktop.
Save quezo/2597979 to your computer and use it in GitHub Desktop.
Better Python Dump
import json
class ObjectEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, object):
return obj.__dict__
raise TypeError(repr(obj) + " is not JSON serializable")
def dumps(obj):
return ObjectEncoder().encode(obj)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment