Soru

Zorluk: OrtaInterpreting JSON Encoded Data

A network technician parses telemetry data returned by a Cisco vManage REST API call stored in a Python dictionary variable named `telemetry_data`:

{
"header": {
"generated_at": 1690000000,
"status": "success"
},
"data": [
{
"device_id": "10.10.10.1",
"interfaces": [
{
"name": "GigabitEthernet1",
"rx_errors": 0,
"tx_errors": 12,
"status": "up"
},
{
"name": "GigabitEthernet2",
"rx_errors": 45,
"tx_errors": 3,
"status": "up"
}
]
},
{
"device_id": "10.10.10.2",
"interfaces": [
{
"name": "GigabitEthernet1",
"rx_errors": 108,
"tx_errors": 0,
"status": "down"
}
]
}
]
}

What specific value is extracted when referencing `telemetry_data["data"][1]["interfaces"][0]["rx_errors"]`?

  1. 108Cevap
  2. B
    0
  3. C
    45
  4. D
    "GigabitEthernet1"

Cevap

108
JSON arrays use 0-based indexing. Traversing `telemetry_data["data"][1]` selects the second device entry (`device_id: "10.10.10.2"`). Navigating into its `"interfaces"` array at index `[0]` selects the dictionary for `GigabitEthernet1`. Evaluating the key `"rx_errors"` yields the value `108`.

Adım Adım Çözüm

1
Locate the top-level key "data" in the JSON object.
Returns an array containing two device objects.
The key "data" maps directly to an array of objects.
2
Access index 1 of the "data" array.
Selects the second device object with device_id "10.10.10.2".
JSON arrays are 0-indexed; index 1 specifies the second item.
3
Locate the key "interfaces" within the second device object.
Returns an array containing one interface object for GigabitEthernet1.
The key "interfaces" maps to a list of interface dictionaries for this device.
4
Access index 0 of the "interfaces" array and retrieve the value of key "rx_errors".
Retrieves the value 108.
Index 0 refers to the first interface object, where the key "rx_errors" holds the numeric value 108.

Anahtar Kavram

JSON Data Traversal and Array Indexing
Tahmini Süre:1m 0s
Bu soruyu puanla