How to return JSON response from Flask view?

Java

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

1
Answers

Replies

In order to return a JSON response, you will need to pass the summary data to the jsonify function. Below is the code that will help you in passing the summary data to the jsonify function. 



from flask import jsonify



@app.route('/summary')


def summary():


    d1 = make_summary()


    return jsonify(d1)

 
 

If you want to unleash your potential in this competitive field, please visit the Java course page for more information, where you can find the Java tutorials and Java frequently asked interview questions and answers as well.

 

This topic has been locked/unapproved. No replies allowed

Login to participate in this discussion.

Leave a reply

Before proceeding, please check your email for a verification link. If you did not receive the email, click here to request another.