Recall & Review
beginner
What Flask method do you use to get JSON data sent in a POST request?
You use
request.get_json() to access JSON data sent in a POST request in Flask.Click to reveal answer
beginner
How do you import the object needed to access JSON data in Flask?You import <code>request</code> from <code>flask</code> like this: <code>from flask import request</code>.Click to reveal answer
beginner
What type of data does
request.get_json() return?It returns a Python dictionary representing the JSON data sent by the client.
Click to reveal answer
intermediate
What happens if the incoming request does not contain valid JSON and you call
request.get_json()?By default, it returns
None if the JSON is missing or invalid.Click to reveal answer
intermediate
How can you safely access a key from JSON data in Flask to avoid errors if the key is missing?
Use the dictionary
.get() method on the JSON data, like data.get('key'), which returns None if the key is missing.Click to reveal answer
Which Flask object do you use to access JSON data sent by a client?
✗ Incorrect
The
request object holds data sent by the client, including JSON.What does
request.get_json() return if the request has no JSON data?✗ Incorrect
By default,
request.get_json() returns None if no JSON is present.How do you import the
request object in Flask?✗ Incorrect
You import
request from the flask module using from flask import request.If you want to safely get a value from JSON data without risking a KeyError, what should you do?
✗ Incorrect
Using
data.get('key') returns None if the key is missing, avoiding errors.Which HTTP method usually carries JSON data that you want to access with
request.get_json()?✗ Incorrect
JSON data is commonly sent in the body of POST requests.
Explain how to access JSON data sent by a client in a Flask route.
Think about the Flask object that holds request data and the method to parse JSON.
You got /3 concepts.
Describe what happens if you call request.get_json() but the client sends no JSON data.
Consider the default behavior of get_json when JSON is missing.
You got /3 concepts.