Created
May 28, 2014 14:44
-
-
Save sloat/61f9fbb5475a4c6c1b30 to your computer and use it in GitHub Desktop.
Extended JSON encoder for flask
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
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