A network administrator parses a JSON response payload from a Cisco Catalyst Center API call stored in a Python dictionary variable named `inventory_data`:
{
"response": [
{
"hostname": "Core-SW-01",
"platformId": "C9300-48U",
"upTimeMinutes": 21600,
"stackMembers": ["Core-SW-01A", "Core-SW-01B"]
},
{
"hostname": "Dist-SW-01",
"platformId": "C9200-24P",
"upTimeMinutes": 61200,
"stackMembers": ["Dist-SW-01A"]
}
],
"version": "1.0"
}
Which Python expression correctly extracts the string value `'Core-SW-01B'` from the payload?
- inventory_data["response"][0]["stackMembers"][1]Answer
- Binventory_data["response"][1]["stackMembers"][0]
- Cinventory_data["response"][0]["stackMembers"][2]
- Dinventory_data["response"]["hostname"]["Core-SW-01"]["stackMembers"][1]
Answer
inventory_data["response"][0]["stackMembers"][1]
The key 'response' maps to a JSON array (list). The first element at index 0 is the object representing the device 'Core-SW-01'. Within this object, the key 'stackMembers' holds another array of strings. Because Python lists use zero-based indexing, the second item 'Core-SW-01B' is located at index 1. Therefore, `inventory_data["response"][0]["stackMembers"][1]` correctly extracts the target value.
Step-by-Step Solution
Key Concept
JSON Array and Object Traversal using Python Indexing
Estimated Time:1m 15s