Created
May 4, 2012 21:54
-
-
Save quezo/2597979 to your computer and use it in GitHub Desktop.
Better Python Dump
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 | |
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