Skip to content

Instantly share code, notes, and snippets.

@sloat
Created May 28, 2014 14:44
Show Gist options
  • Save sloat/61f9fbb5475a4c6c1b30 to your computer and use it in GitHub Desktop.
Save sloat/61f9fbb5475a4c6c1b30 to your computer and use it in GitHub Desktop.
Extended JSON encoder for flask
from flask import json
class ExJSONEncoder(json.JSONEncoder):
'''Extended JSON encoder for more type support'''
def default(self, o):
if isinstance(o, set):
return list(o)
elif isinstance(o, arrow.Arrow):
o = o.datetime
elif isinstance(o, Decimal):
return str(o)
return super(ExJSONEncoder, self).default(o)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment