Exercises
JSON
3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.
Exercise 1Passed
Turn the dictionary into JSON text and print it.
Python
import json
data = {"name": "Ada", "born": 1815}
# print it as JSON
dumps is dump-to-string.
import json
data = {"name": "Ada", "born": 1815}
print(json.dumps(data))Exercise 2Passed
Parse the JSON text and print the name.
Python
import json
text = '{"name": "Ada", "born": 1815}'
# print Ada
loads turns a string into Python.
import json
text = '{"name": "Ada", "born": 1815}'
print(json.loads(text)["name"])Exercise 3Passed
A date is not JSON serializable. Convert it so this prints valid JSON.
Python
import json
from datetime import date
print(json.dumps({"when": date(2026, 3, 14)}))isoformat() gives a string JSON understands.
import json
from datetime import date
print(json.dumps({"when": date(2026, 3, 14).isoformat()}))