Courseiva
Software Development and DesignmediumMultiple ChoiceObjective-mapped

200-901 Software Development and Design Practice Question

A Python script reads a JSON configuration file named 'config.json' and needs to extract the value of a nested key 'api_key' under 'authentication'. The file structure is: {"authentication": {"api_key": "abc123", "method": "token"}, "timeout": 30}. Which code snippet correctly opens the file and retrieves the api_key value?

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') as f: data = json.load(f) key = data['authentication']['api_key']

Using the json module and context manager is the standard approach; the nested key is accessed via dictionary indexing.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • f = open('config.json'); data = json.load(f); key = data['authentication']['api_key']; f.close()

    Why it's wrong here

    Works but not using context manager; less safe (can forget close).

  • with open('config.json') as f: data = json.loads(f) key = data['authentication']['api_key']

    Why it's wrong here

    json.loads expects a string, not a file object.

  • with open('config.json', 'r') as f: data = json.load(f) key = data['authentication.api_key']

    Why it's wrong here

    Nested keys require separate brackets; dot notation is not used.

  • with open('config.json') as f: data = json.load(f) key = data['authentication']['api_key']

    Why this is correct

    json.load() reads file and parses JSON; correct nested access.

About these practice questions

Courseiva writes every 200-901 question from scratch — 989 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

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.