200-901 Software Development and Design Practice Question
A developer is building a Python function that must parse a JSON payload returned by a Cisco DNA Center API. The function needs to gracefully handle cases where the JSON is malformed or the response body is empty, without crashing the calling script. Which approach best meets this requirement?
⚠ Common exam trap
The trap here is assuming that any non-empty response body is valid JSON and that parsing errors should be handled by the caller rather than within the function.
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
✓
Wrap json.loads() in a try/except json.JSONDecodeError block and return a default value or raise a custom exception when parsing fails.
The function must isolate JSON parsing failures so the caller is not disrupted by malformed or empty responses. Catching json.JSONDecodeError around json.loads() and returning a default or raising a custom exception centralizes error handling and provides a predictable interface. The other choices either propagate exceptions, introduce security risks with eval(), or defer parsing without handling errors.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
- ✗
Use eval() to interpret the response body, since eval() can parse both JSON and Python literals.
Why it's wrong here
eval() executes arbitrary code and is a serious security risk when processing untrusted API responses. It also does not correctly handle JSON constructs like null, true, and false, which are not valid Python literals. This approach introduces vulnerabilities and parsing errors rather than graceful handling of malformed or empty JSON.
- ✗
Check if the response body is empty and, if not, pass it directly to the rest of the application as a string.
Why it's wrong here
Passing the raw string defers parsing to other parts of the application, spreading error handling across many modules. It also does not address malformed JSON that is non-empty, which would still cause failures downstream. The requirement asks for a function that handles parsing errors centrally and gracefully, which this approach does not provide.
- ✓
Wrap json.loads() in a try/except json.JSONDecodeError block and return a default value or raise a custom exception when parsing fails.
Why this is correct
json.loads() raises json.JSONDecodeError for malformed input, and empty strings also trigger this exception. Catching it inside the function localizes the failure, allowing the function to return a safe default or a meaningful custom exception. This keeps the calling script stable and provides a clean contract for callers, directly meeting the graceful-handling requirement.
- ✗
Call json.loads() on the response body and let any exception propagate to the caller.
Why it's wrong here
Allowing exceptions to propagate means malformed or empty JSON will crash the calling script unless every caller wraps the function in its own try/except, which defeats the purpose of centralized error handling. It also fails to provide a graceful fallback for empty bodies, so this approach does not satisfy the requirement of preventing crashes in the broader application.
Go deeper
Related to this question
About these practice questions
This 200-901 question is part of Courseiva's 975-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 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.