Skip to content

Instantly share code, notes, and snippets.

@juztin
juztin / gist:c997c197fadfa870c816
Created February 12, 2015 22:43
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)