Parse a User Profile JSON

Easy ⏱ 8 min 80% acceptance ★★★★★ 4.8
Write user_summary(raw) that parses a JSON string like '{"name": "Asha", "age": 29}' with json.loads and returns 'Asha (29)'. Missing keys should fall back to 'unknown' and 0 via .get.

Examples

Example 1
Input
user_summary('{"name": "Asha", "age": 29}')
Output
'Asha (29)'
Explanation

The string became a dict, then formatted.

Constraints

  • Use json.loads.
  • Defaults via dict.get.

Topics

JSONloads

Companies

TCSSalesforceInfosys

Hints

Hint 1

loads returns native Python objects.

Hint 2

f-string the two fields.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.