Bird
Raised Fist0

You have a JSON file users.json containing a list of user dictionaries. How do you load it and print the name of each user?

hard🚀 Application Q8 of Q15
Python - Structured Data Files

You have a JSON file users.json containing a list of user dictionaries. How do you load it and print the name of each user?

Awith open('users.json') as f: users = json.dumps(f) for user in users: print(user['name'])
Bwith open('users.json') as f: users = json.loads(f) for user in users: print(user['name'])
Cwith open('users.json') as f: users = json.load(f) for user in users: print(user['name'])
Dwith open('users.json') as f: users = json.dump(f) for user in users: print(user['name'])
Step-by-Step Solution
Solution:
  1. Step 1: Load JSON list from file

    json.load(f) reads JSON data from file as Python list of dicts.
  2. Step 2: Iterate and print each user's name

    Loop through list and access each dict's 'name' key to print.
  3. Final Answer:

    Use json.load() and loop: with open('users.json') as f: users = json.load(f); for user in users: print(user['name']) -> Option C
  4. Quick Check:

    Load JSON list with json.load(), then iterate [OK]
Quick Trick: Use json.load() for files, then loop over list [OK]
Common Mistakes:
MISTAKES
  • Using json.dumps() or dump() incorrectly
  • Not iterating over list

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Python Quizzes