An automated Python monitoring script sends a RESTCONF HTTP GET request to a Cisco IOS XE router to inspect BGP peer relationships. The JSON response is parsed into a Python dictionary named `bgp_data` as shown below:
{
"Cisco-IOS-XE-bgp:bgp": {
"bgp": [
{
"asn": 65001,
"neighbor": [
{
"ip": "10.1.1.2",
"remote-as": 65002,
"state": "Established"
},
{
"ip": "10.2.2.2",
"remote-as": 65003,
"state": "Active"
}
]
}
]
}
}
Which Python expression correctly evaluates to the string `"Active"`?
- bgp_data["Cisco-IOS-XE-bgp:bgp"]["bgp"][0]["neighbor"][1]["state"]Answer
- Bbgp_data["Cisco-IOS-XE-bgp:bgp"]["bgp"][1]["neighbor"][1]["state"]
- Cbgp_data["Cisco-IOS-XE-bgp:bgp"]["bgp"][0]["neighbor"][2]["state"]
- Dbgp_data["Cisco-IOS-XE-bgp:bgp"]["bgp"]["neighbor"][1]["state"]
Answer
bgp_data["Cisco-IOS-XE-bgp:bgp"]["bgp"][0]["neighbor"][1]["state"]
The correct expression traverses the top-level dictionary key `"Cisco-IOS-XE-bgp:bgp"`, selects the single element in the `"bgp"` array using index `0`, accesses the second object in the `"neighbor"` array using index `1`, and reads the string value associated with the `"state"` key, correctly yielding `"Active"`.
Step-by-Step Solution
Key Concept
Traversing nested JSON dictionaries and zero-indexed arrays in REST API responses
Estimated Time:1m 0s