Fix the JSON Parsing Bug
Intermediate · Fix the bug · from Python JSON: Parse, Create, and Manipulate JSON Data
From the lesson: Python JSON: Parse, Create, and Manipulate JSON Data
Imagine a universal language that every app, website, and database can understand. That's JSON (JavaScript Object Notation). It's the most popular format for sending data between computers.
Read the lessonThis code tries to parse a JSON string and print a nested value, but it crashes. Fix the bug so it prints the expected output.
Expected output:
Language: Pythonimport json
json_str = '{"course": {"name": "Intro to Programming", "language": "Python"}}'
data = json.loads(json_str)
print(f'Language: {data["language"]}')
More JSON exercises
- Parse a JSON StringBeginner
- Predict the JSON OutputBeginner
- Create Pretty JSONIntermediate
- Refactor String Concatenation to json.dumpsIntermediate
- Extract Data from Nested API JSONAdvanced
All Python exercises · 50 practice problems · File I/O & Data Formats quiz