Skip to content

Instantly share code, notes, and snippets.

@juztin
Created February 12, 2015 22:43
Show Gist options
  • Save juztin/c997c197fadfa870c816 to your computer and use it in GitHub Desktop.
Save juztin/c997c197fadfa870c816 to your computer and use it in GitHub Desktop.
Python JSON Decimal/time Encoder
class JSONEncoder(json.JSONEncoder):
"""JSONEncoder that handles decimal and time types.
"""
def default(self, o):
if isinstance(o, decimal.Decimal):
return float(o)
elif hasattr(o, 'isoformat'):
return o.isoformat()
return super(DecimalEncoder, self).default(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment