← Python from Scratch
Lesson 54 of 78 · 5 XP
Warm-up: a dictionary as text warm-up
Theory and problem statement
Machine translation, not yet reviewed by a native speaker.
JSON is a text format programs use to exchange data. The json module turns a dictionary into such text with json.dumps:
import json
print(json.dumps({"x": 1})) # {"x": 1}
In JSON strings are always in double quotes.
Task. Write a function to_json(d) that returns the dictionary d as JSON text.
Sign up for free to solve this task right in your browser: code editor, running, test checks and hints.