Courseiva

200-901 Software Development and Design Practice Question

A developer is creating a Python function that must parse a JSON response from a Cisco DNA Center API. The function should handle cases where a key may be missing without crashing. Which approach best achieves this?

⚠ Common exam trap

The trap here is assuming that direct key access with exception handling is equivalent to using get(), but get() is simpler and more readable for optional keys.

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

✓

Use response.json().get('key', default_value) to retrieve values with a fallback.

The get() method on a dictionary provides a safe way to access keys that may be absent, returning a default value instead of raising an exception. This is particularly useful when parsing JSON from APIs where fields are optional. The other options either rely on error-prone exception handling, are overly complex, or use inappropriate parsing techniques. Using get() results in clean, robust code.

Answer analysis

Option-by-option breakdown

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

  • ✗

    Convert the JSON response to a string and use regular expressions to extract values.

    Why it's wrong here

    Parsing JSON with regular expressions is fragile and not recommended. JSON structure can vary, and regex patterns may break with formatting changes or nested objects. The json() method already provides a native Python dictionary, so using regex adds unnecessary complexity and potential for bugs. This approach is not maintainable for API responses.

  • ✗

    Use a try/except block around each key access to catch KeyError and assign a default.

    Why it's wrong here

    While try/except can handle missing keys, wrapping each access individually is verbose and less efficient than using get(). It also obscures the intent of providing defaults. For multiple keys, the code becomes cluttered with exception handling, whereas get() offers a concise and consistent way to manage missing data in JSON parsing.

  • ✗

    Use response.json() and access keys directly with square brackets, relying on exception handling.

    Why it's wrong here

    Direct key access with square brackets raises a KeyError if the key is missing, which would require a try/except block to handle. This adds unnecessary complexity and does not proactively handle missing keys. It is less clean and more error-prone than using the get() method, which returns None by default for missing keys.

  • ✓

    Use response.json().get('key', default_value) to retrieve values with a fallback.

    Why this is correct

    The get() method on a dictionary returns the value for the specified key if it exists, and otherwise returns a provided default value. This avoids KeyError exceptions and allows the function to continue gracefully. It is the idiomatic Python way to handle optional keys in JSON responses, making the code robust and readable.

About these practice questions

One of 975 original 200-901 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written and reviewed by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

Last reviewed September 2026 · checked against the official Cisco exam blueprint

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.