Complete the code to get JSON data from a Flask request.
data = request.[1]()The get_json() method extracts JSON data from the request body in Flask.
Complete the code to access the value of the 'name' key from JSON data.
name = data[1]"name"]
JSON data parsed into a Python dictionary is accessed using square brackets [] with the key as a string.
Fix the error in accessing nested JSON data for key 'address' then 'city'.
city = data["address"][1]"city"]
To access nested dictionary keys, use square brackets for each key step.
Fill both blanks to safely get the 'age' key from JSON data with a default of 0.
age = data.[1]("age", [2])
The get method retrieves a key's value or returns the default if the key is missing.
Fill all three blanks to create a Flask route that accepts JSON POST requests and returns the 'status' key.
from flask import Flask, request, jsonify app = Flask(__name__) @app.route('/status', methods=[[1]]) def get_status(): data = request.[2]() status = data.get([3], 'unknown') return jsonify({'status': status})
The route must accept POST requests, use get_json() to get JSON data, and access the 'status' key.