Editor

Extract Data from Nested API JSON

Advanced · Write the code · 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 lesson

You are given a JSON string representing an API response with a list of users. Parse it and print each user's name and their first hobby.

The JSON data:

{"users": [{"name": "Alice", "hobbies": ["chess", "piano"]}, {"name": "Bob", "hobbies": ["soccer", "cooking"]}, {"name": "Charlie", "hobbies": ["painting", "yoga"]}]}

Expected output:

Alice likes chess
Bob likes soccer
Charlie likes painting
import json
json_str = '{"users": [{"name": "Alice", "hobbies": ["chess", "piano"]}, {"name": "Bob", "hobbies": ["soccer", "cooking"]}, {"name": "Charlie", "hobbies": ["painting", "yoga"]}]}'
# Your code here

More JSON exercises

All Python exercises · 50 practice problems · File I/O & Data Formats quiz