Skip to content

Instantly share code, notes, and snippets.

@emre
Created May 27, 2011 14:49
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emre/995397 to your computer and use it in GitHub Desktop.
Save emre/995397 to your computer and use it in GitHub Desktop.
mongodb, flask, better than jsonify
class MongoEncoder(json.JSONEncoder):
def _iterencode(self, o, markers=None):
if isinstance(o, ObjectId):
return str(o)
else:
return json.JSONEncoder._iterencode(self, o, markers)
def smart_json_response(data):
data = json.dumps(data, cls = MongoEncoder, indent=4)
return current_app.response_class(data, mimetype='application/json')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment