Skip to content
Foxipa
Code Completion 4 Challenges

Complete the Python JSON code

Practice serializing Python data, reading JSON text, and working with JSON files.

Intermediate ~8 min read

Challenge 1

Convert the Python value to a JSON string.

python Your answer
import json

data = {"name": "Ada", "score": 10}
text = 
print(text)

Press Ctrl⌘Enter to check your answer

Challenge 2

Convert the JSON string into its Python value.

python Your answer
import json

text = '[1, 2, 3]'
data = 
print(data)

Press Ctrl⌘Enter to check your answer

Challenge 3

Write the Python value to the open UTF-8 text file as JSON.

python Your answer
import json

value = {"ready": True}
with open("data.json", "w", encoding="utf-8") as file:
    

Press Ctrl⌘Enter to check your answer

Challenge 4

Read the JSON value from the open UTF-8 text file.

python Your answer
import json

with open("data.json", encoding="utf-8") as file:
    value = 
print(value)

Press Ctrl⌘Enter to check your answer