0
0
Rest APIprogramming~10 mins

JSON as standard format in Rest API - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to set the Content-Type header to JSON.

Rest API
headers = {"Content-Type": "[1]"}
Drag options to blanks, or click blank then click option'
Aapplication/json
Btext/html
Capplication/xml
Dtext/plain
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text/html' or 'application/xml' instead of 'application/json'.
2fill in blank
medium

Complete the code to convert a Python dictionary to a JSON string.

Rest API
import json
json_data = json.[1](data)
Drag options to blanks, or click blank then click option'
Adumps
Bload
Cdump
Dloads
Attempts:
3 left
💡 Hint
Common Mistakes
Using load or loads which are for reading JSON.
3fill in blank
hard

Fix the error in the code to parse JSON from a string.

Rest API
import json
parsed = json.[1](json_string)
Drag options to blanks, or click blank then click option'
Adump
Bdumps
Cloads
Dload
Attempts:
3 left
💡 Hint
Common Mistakes
Using load which reads from a file, not a string.
4fill in blank
hard

Fill both blanks to create a JSON response with status code 200.

Rest API
response = [1](json.dumps(data), [2]=200, headers=headers)
Drag options to blanks, or click blank then click option'
Amake_response
Bjsonify
Cstatus
Dcontent_type
Attempts:
3 left
💡 Hint
Common Mistakes
Using jsonify which returns a response but does not accept status code like this.
5fill in blank
hard

Fill all three blanks to extract a value from JSON request data.

Rest API
from flask import request
json_data = request.[1]
value = json_data.get([2], [3])
Drag options to blanks, or click blank then click option'
Ajson
B"key"
CNone
Dargs
Attempts:
3 left
💡 Hint
Common Mistakes
Using args which is for query parameters, not JSON body.