Skip to content

Instantly share code, notes, and snippets.

@pgjones
Created April 24, 2016 19:27
Show Gist options
  • Save pgjones/74e95ddf35efc3bff106f26d36638b99 to your computer and use it in GitHub Desktop.
Save pgjones/74e95ddf35efc3bff106f26d36638b99 to your computer and use it in GitHub Desktop.
A replacement flask response to automatically jsonify dicts use with app.response_class = JSONResponse
from flask import jsonify, Response
class JSONResponse(Response):
@classmethod
def force_type(cls, value, environ=None):
if isinstance(value, dict):
value = jsonify(value)
return super().force_type(value, environ)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment