REST API Data Parser
Advanced
30 XP
You're trying this as a guest: your result shows here but isn't saved.
Sign in
Parse nested JSON data like a real API response — a critical skill for backend and data engineering roles.
You're given a JSON string representing a list of users from an API. Write a function parse_users(json_str) that:
- Parses the JSON string.
- Extracts each user's name, email, and city (nested under address).
- Returns a list of dicts:
[{'name': ..., 'email': ..., 'city': ...}]
- If any field is missing, use 'N/A' as the default.
- If the JSON is malformed, return an empty list.
To pass
- Parse user with all fields present
- Handle missing email with N/A
- Handle missing address/city with N/A
- Return empty list for malformed JSON
Need a hint?
- Use json.loads() inside a try/except json.JSONDecodeError block.
- Use dict.get('key', 'N/A') to safely access keys with a default.
- For nested access: item.get('address', {}).get('city', 'N/A') — the empty dict {} prevents AttributeError.