Chapters
Python114 chapters

Exercises

JSON

3 tasks. Write the code, press Check, and the page runs it against a real Python interpreter.

Exercise 1

Turn the dictionary into JSON text and print it.

Python
import json

data = {"name": "Ada", "born": 1815}
# print it as JSON
Exercise 2

Parse the JSON text and print the name.

Python
import json

text = '{"name": "Ada", "born": 1815}'
# print Ada
Exercise 3

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)}))