Question

Difficulty: EasyInterpreting JSON Encoded Data

A network administrator receives the following JSON payload from a Cisco DNA Center REST API request:

{
"response": [
{
"hostname": "Switch-Core-01",
"managementIp": "10.1.10.1"
},
{
"hostname": "Switch-Access-01",
"managementIp": "10.1.20.15"
}
]
}

What is the value of `response[1]["managementIp"]` in this JSON structure?

  1. "10.1.20.15"Answer
  2. B
    "10.1.10.1"
  3. C
    ["10.1.10.1", "10.1.20.15"]
  4. D
    "Switch-Access-01"

Answer

The value of `response[1]["managementIp"]` is "10.1.20.15".
JSON uses 0-based indexing for array structures defined by square brackets (`[]`). The key `"response"` maps to an array containing two objects. The first element at index `0` corresponds to `Switch-Core-01`, and the second element at index `1` corresponds to `Switch-Access-01`. Accessing key `"managementIp"` on the second element yields `"10.1.20.15"`.

Step-by-Step Solution

1
Locate the top-level key named "response".
The key "response" contains an array holding two object structures.
Top-level access requires locating the target key first.
2
Apply the array index [1] using 0-based indexing.
Index [0] corresponds to the first object (Switch-Core-01), while index [1] targets the second object (Switch-Access-01).
JSON arrays use 0-based indexing.
3
Extract the value associated with the key "managementIp" from the second object.
The key "managementIp" maps to the string value "10.1.20.15".
Accessing the key within the targeted dictionary/object yields its corresponding value.

Key Concept

JSON Data Structure Traversal and Zero-Based Array Indexing
Rate this question