200-901 Software Development and Design Practice Question
A developer needs to read a JSON configuration file and parse it into a Python dictionary. The file contains nested objects. Which code snippet correctly accomplishes this?
Answer choices
Why each option matters
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
with open('config.json', 'r') as f: data = json.load(f)
The correct approach is to open the file with a context manager and use json.load() with the file object to parse the JSON directly into a Python dictionary. json.loads() is for parsing a JSON string, not a file object.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
with open('config.json', 'r') as f: data = json.loads(f)
Why it's wrong here
json.loads() expects a string, not a file object; json.load() is used with file objects.
- ✗
data = json.loads(open('config.json', 'r').read())
Why it's wrong here
This works but is not best practice because it doesn't close the file properly; using 'with' is recommended.
- ✓
with open('config.json', 'r') as f: data = json.load(f)
Why this is correct
json.load() reads the file and parses it directly into a Python object.
- ✗
with open('config.json', 'r') as f: data = json.dumps(f.read())
Why it's wrong here
json.dumps() converts a Python object to a JSON string, not the other way.
Go deeper
Related to this question
About these practice questions
This 200-901 question is part of Courseiva's 989-question bank — original exam-style content with full explanations and wrong-answer analysis, never real exam questions or exam dumps. Learn why practice questions differ from exam dumps →
JA
Written by Johnson Ajibi, MSc IT Security
Senior Network & Security Engineer · founder of Courseiva
This 200-901 practice question is part of Courseiva's free Cisco certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the 200-901 exam.