300-435 · Question #3
Refer to the exhibit. A Python script has been created that calls the Cisco SD-WAN vManage Device Inventory API to get the list of vEdges. The JSON data that returns to a Python dictionary has been…
The correct answer is A. d["data"][0]["host-name"]. To access the hostname from the given JSON structure, which is converted to a Python dictionary d, one must navigate through the dictionary keys and list indices appropriately.
Question
Options
How the community answered
(29 responses)- A76% (22)
- B14% (4)
- C3% (1)
- D7% (2)
Why each option
To access the hostname from the given JSON structure, which is converted to a Python dictionary `d`, one must navigate through the dictionary keys and list indices appropriately.
The exhibit shows JSON with a top-level key "data" that contains a list of objects. To access the first element of this list, `d["data"][0]` is used, and then `["host-name"]` is appended to retrieve the value associated with that key within the object, correctly following Python dictionary and list indexing rules.
Dictionary keys in Python must be quoted strings, so `d[data]` is incorrect; it should be `d["data"]`.
Parentheses `(0)` are used for function calls, not for indexing lists or accessing dictionary elements by key in Python; square brackets `[0]` are required.
This path reverses the order of keys and incorrectly uses parentheses for indexing, as "host-name" is nested within an item of the "data" list, not the other way around.
Concept tested: Python dictionary and JSON data parsing
Source: https://docs.python.org/3/tutorial/datastructures.html#dictionaries
Topics
Community Discussion
No community discussion yet for this question.