Skip to content
Advertisement

Return JSON response from Flask view

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?

JavaScript

Advertisement

Answer

A view can directly return a Python dict or list and Flask will call jsonify automatically.

JavaScript

For older Flask versions, or to return a different JSON-serializable object, import and use jsonify.

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement