350-401 · Question #702
Refer to the exhibit. Which Python code parses the response and prints "18:32:21.474 UTC Sun Mar 10 2019"?
The correct answer is B. print(response[result']['body']['simple_time']}. To correctly extract a specific value from a nested JSON structure in Python, you must use a sequence of dictionary key accesses matching the data's hierarchy.
Question
Refer to the exhibit. Which Python code parses the response and prints "18:32:21.474 UTC Sun Mar 10 2019"?
Exhibits
Options
- Aprint(response['resut'][0||'simple_time']}
- Bprint(response[result']['body']['simple_time']}
- Cprint(response['body']['simple_time']}
- Dprint(response[jresult']['body']['simple_time']}
How the community answered
(46 responses)- A7% (3)
- B76% (35)
- C13% (6)
- D4% (2)
Why each option
To correctly extract a specific value from a nested JSON structure in Python, you must use a sequence of dictionary key accesses matching the data's hierarchy.
This option contains a typo ('resut' instead of 'result') and uses an incorrect indexing or access method ('[0||'simple_time']'), which is not valid Python syntax for dictionary access.
Given a JSON response where 'simple_time' is nested within 'body', which is itself nested within 'result', the correct Python code to access this value is `response['result']['body']['simple_time']`. This path correctly navigates through the dictionary keys to retrieve the desired string.
This option incorrectly assumes that 'body' is a top-level key directly under 'response', skipping the 'result' key in the JSON structure.
This option contains a typo ('jresult' instead of 'result'), which would cause a KeyError when attempting to access the dictionary.
Concept tested: Python JSON parsing and dictionary access
Source: https://docs.python.org/3/library/json.html#json.loads
Topics
Community Discussion
No community discussion yet for this question.

