Complete the code to import the function that helps create JSON responses in Flask.
from flask import [1]
The jsonify function is used to create JSON responses in Flask easily.
Complete the code to return a JSON response with a message using jsonify.
return [1]({'message': 'Hello, world!'})
The jsonify function wraps the dictionary and returns a proper JSON response.
Fix the error in the code to correctly return a JSON response with a status code 201.
return jsonify({'status': 'created'}), [1]
Status code 201 means the resource was created successfully and is the correct code here.
Fill both blanks to create a Flask route that returns a JSON response with a list of users.
@app.route('/users') def get_users(): users = ['Alice', 'Bob', 'Charlie'] return [1]({'users': [2])
The jsonify function is used to return JSON, and the users list is passed as the value.
Fill all three blanks to create a Flask route that accepts POST requests and returns a JSON response with the posted data.
@app.route('/submit', methods=[[1]]) def submit(): data = [2].get_json() return [3]({'received': data})
The route must accept 'POST' requests, use request.get_json() to get JSON data, and return it with jsonify.