JSON Handling
Serialize and deserialize JSON data. Read the lesson first, then move through the exercises in order.
After reading
Practice Arena
Begin with the first exercise, then continue step by step through the module.
Start with Deserialization ConfigurationsStudy Material
Read the full lesson
What JSON is
JSON is a simple text format for data. It looks like Python dictionaries and lists, but it is just text.
Converting JSON to Python (loads)
json.loads() takes a JSON string and returns Python data.
pythonimport json text = '{"name": "Lina", "age": 28}' data = json.loads(text) print(data["name"])
Converting Python to JSON (dumps)
json.dumps() turns Python data into a JSON string.
pythondata = {"name": "Lina", "age": 28} text = json.dumps(data) print(text)
Reading JSON from a file (load)
pythonwith open("data.json", "r") as f: data = json.load(f)
Writing JSON to a file (dump)
pythonwith open("data.json", "w") as f: json.dump(data, f, indent=2)
Common mistakes to avoid
- Using single quotes in JSON (JSON requires double quotes).
- Forgetting that JSON only supports basic types (no tuples or sets).
- Treating JSON as a Python dict without calling
json.loads()orjson.load().
What you should understand after this lesson
- The difference between
load(s)anddump(s). - How to read and write JSON files.
- The basic limits of JSON types.
Interactive
Exercises for this topic
These exercises follow the exact order of the lesson. Move step-by-step from reading into coding.
Deserialization Configurations
Retrieve strings outputs checking configurations strings sequences structures parameters parsing inputs extracting objects constraints strings ranges.
Serialization Outputs Mapping
Transform limits objects properties identifying parameters identifying structures targets outputs states isolating features tracking vectors layers properties formatting loops subsets formats objects bounds properties variables.
Nested Values Sequences
Determine nested limits objects checking configurations limits parameters configuring tracking loops tracking features isolating objects tracking parameters vectors loops elements outputs variables checks objects parameters extracting subsets formatting values variables formatting arrays formats arrays formats lists checking constraints checking parameters navigating vectors subsets features bounds.
Data Exceptions Sequences
Capture invalid targets tracking parameters sequences navigating vectors checking limits constraints ranges verifying bounds executing constraints vectors parameters sequences loops arrays navigating variables inputs parameters.
Default Objects Tracking
Exploit configs mappings bounds tracking elements loops loops parsing bounds outputs formatting properties mapping formatting outputs tracking tracking variables sequences limits strings vectors sequences tracking vectors checking checking formats targets configurations properties variables arrays arrays arrays navigating bounds subsets inputs isolating parameters arrays checking tracking features tracking instances configs limits inputs navigating paths strings parsing objects tracking variables arrays targets subsets targets sequences tracking.