Posted By: Anonymous
I have a function that analyzes a CSV file with Pandas and produces a dict with summary information. I want to return the results as a response from a Flask view. How do I return a JSON response?
@app.route("/summary") def summary(): d = make_summary() # send it back as json
EDIT: As of Flask 1.1.0 (as mentioned by Adrien Ball in comment below), you can now directly return a python dict and Flask will jsonify it behind the scenes for you
@app.route('/summary') def summary(): d = make_summary() return d
if you want to return a different json-serializable object, you can import and use
from flask import jsonify ... return jsonify(x)