Question

Difficulty: HardInterpreting JSON Encoded Data

A network automation script executes a REST API call to a Cisco SD-WAN vManage controller to retrieve operational statistics. The API returns the following JSON payload:

{
"system_status": {
"controller_group": "Group-Alpha",
"devices": [
{
"hostname": "vEdge-Branch1",
"site_id": 100,
"reachability": "reachable",
"tunnel_stats": [
{"color": "biz-internet", "latency_ms": 12},
{"color": "mpls", "latency_ms": 8}
]
},
{
"hostname": "vEdge-Branch2",
"site_id": 200,
"reachability": "unreachable",
"tunnel_stats": [
{"color": "biz-internet", "latency_ms": 45}
]
}
]
}
}

Assuming the response is stored in a Python dictionary named `payload`, which data path expression correctly extracts the integer value `8` representing the MPLS tunnel latency for `vEdge-Branch1`?

  1. payload["system_status"]["devices"][0]["tunnel_stats"][1]["latency_ms"]Answer
  2. B
    payload["system_status"]["devices"][1]["tunnel_stats"][1]["latency_ms"]
  3. C
    payload["system_status"]["devices"][0]["tunnel_stats"][2]["latency_ms"]
  4. D
    payload["system_status"]["devices"][0]["tunnel_stats"]["mpls"]["latency_ms"]

Answer

The expression `payload["system_status"]["devices"][0]["tunnel_stats"][1]["latency_ms"]` correctly extracts the integer value 8.
The correct expression accurately navigates the nested JSON hierarchy. The top-level key 'system_status' maps to an object containing the key 'devices', which holds an array (list). Index 0 retrieves the first device ('vEdge-Branch1'). Within that device dictionary, 'tunnel_stats' holds another array. Index 1 retrieves the second tunnel entry ('mpls'), and the key 'latency_ms' yields the value 8.

Step-by-Step Solution

1
Locate the top-level object key 'system_status'
Accesses the object containing 'controller_group' and the 'devices' array.
Top-level JSON element is a dictionary object containing 'system_status'.
2
Access the first element of the 'devices' array
References index [0] to select the dictionary object for 'vEdge-Branch1'.
JSON arrays use zero-based indexing; index 0 represents the first element.
3
Locate the 'tunnel_stats' key within the selected device dictionary
Retrieves the list of tunnel statistics dictionary objects.
'tunnel_stats' contains an array of objects enclosed in square brackets [].
4
Select the second element of the 'tunnel_stats' array and extract 'latency_ms'
Index [1] selects `{"color": "mpls", "latency_ms": 8}`, and key `["latency_ms"]` yields `8`.
Zero-based index 1 points to the second element in the array.

Key Concept

JSON Nested Data Structures and Zero-Based Array Indexing
Rate this question