We're sorry but this app doesn't work properly without JavaScript enabled. Please enable it to continue.

This lesson's interactive features are locked, please to keep using them

Parsing JSON

Parse

The json.loads() function in Python takes a JSON string as input and constructs a Python object (dictionaries and lists) from the string. This allows us to work with the JSON as native Python objects!

import json

json_string = '{"title": "Avengers Endgame", "rating": 4.7, "in_theaters": false}'
obj: dict[str, str | float | bool] = json.loads(json_string)

print(obj["title"])
# Avengers Endgame

Assignment

It's common for developers to write local tests using mock (or fake) data that looks like real data. Let's ensure that the JSON format the backend devs at Jello handed us is valid JSON! It would be a shame to write a bunch of code only to find out the format is wrong.

Complete parse_project function: