nerdexam
Cisco

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.

Controller-Based Network Automation

Question

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 converted and assigned to a variable named "d". A portion of the JSON is shown in the exhibit. Which code will complete the expression hostname: to access the hostname?

Options

  • Ad["data"][0]["host-name"]
  • Bd[data][0]["host-name"]
  • Cd"data"["host-name"]
  • Dd["host-name"]"data"

How the community answered

(29 responses)
  • A
    76% (22)
  • B
    14% (4)
  • C
    3% (1)
  • D
    7% (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.

Ad["data"][0]["host-name"]Correct

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.

Bd[data][0]["host-name"]

Dictionary keys in Python must be quoted strings, so `d[data]` is incorrect; it should be `d["data"]`.

Cd["data"](0)["host-name"]

Parentheses `(0)` are used for function calls, not for indexing lists or accessing dictionary elements by key in Python; square brackets `[0]` are required.

Dd["host-name"]["data"]("0")

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

#Python scripting#JSON parsing#API interaction#Data structures

Community Discussion

No community discussion yet for this question.

Full 300-435 Practice