Skip to content

Instantly share code, notes, and snippets.

@AhnSeongHyun
Last active June 16, 2017 02:20
Show Gist options
  • Save AhnSeongHyun/2329e79ac451edf655789f7243077ef1 to your computer and use it in GitHub Desktop.
Save AhnSeongHyun/2329e79ac451edf655789f7243077ef1 to your computer and use it in GitHub Desktop.
jsonify_encoder
def configure_json_encoder(app):
from decimal import Decimal
class CustomJsonEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, Decimal):
return str(obj)
if obj is None:
return str('')
return super(CustomJsonEncoder, self).default(obj)
app.json_encoder = CustomJsonEncoder
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment