Tutorial by Examples

Flask has a utility called jsonify() that makes it more convenient to return JSON responses from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/get-json') def hello(): return jsonify(hello='world') # Returns HTTP Response with {"hello": "world"} ...
If the mimetype of the HTTP request is application/json, calling request.get_json() will return the parsed JSON data (otherwise it returns None) from flask import Flask, jsonify app = Flask(__name__) @app.route('/api/echo-json', methods=['GET', 'POST', 'DELETE', 'PUT']) ...

Page 1 of 1