Question

Difficulty: MediumInterpreting JSON Encoded Data

A network engineer issues an API call to a Cisco Catalyst Center endpoint to query site health metrics. The API returns the following JSON response payload stored in a Python dictionary named `site_data`:

{
"response": [
{
"siteHierarchy": "Global/USA/SanJose/Building1",
"clientCount": 150,
"healthScore": [
{
"healthType": "OVERALL",
"score": 88
},
{
"healthType": "WIRELESS",
"score": 92
}
]
}
]
}

Which Python expression correctly extracts the numerical score for the WIRELESS health type from `site_data`?

  1. site_data["response"][0]["healthScore"][1]["score"]Answer
  2. B
    site_data["response"][0]["healthScore"][0]["score"]
  3. C
    site_data["response"]["healthScore"][1]["score"]
  4. D
    site_data["response"][0]["healthScore"]["WIRELESS"]["score"]

Answer

site_data["response"][0]["healthScore"][1]["score"]
The expression `site_data["response"][0]["healthScore"][1]["score"]` correctly traverses the data structure step by step: accessing the outer dictionary key "response", selecting the first element (index 0) of the response list, accessing the dictionary key "healthScore", selecting the second element (index 1) of the healthScore list which corresponds to WIRELESS, and finally retrieving the value for the key "score".

Step-by-Step Solution

1
Inspect the root element structure of the JSON payload.
The top-level object is a dictionary with a single key "response", whose value is enclosed in square brackets `[]`, indicating a JSON array (Python list).
Array elements must be accessed using zero-based integer indexing.
2
Navigate into the first element of the "response" list and locate the target array.
`site_data["response"][0]` returns the site dictionary object containing keys like "siteHierarchy", "clientCount", and "healthScore".
Zero-based indexing places the first site dictionary at position [0].
3
Index into the "healthScore" array to access the WIRELESS health object.
The "healthScore" key contains a list of two objects: index [0] is OVERALL and index [1] is WIRELESS.
Accessing `["healthScore"][1]` selects the dictionary `{"healthType": "WIRELESS", "score": 92}`.
4
Extract the target key value from the selected dictionary.
Appending `["score"]` retrieves the integer value 92.
Standard dictionary key access retrieves the value paired with the specified string key.

Key Concept

Data extraction from nested JSON structures containing combinations of objects and arrays
Rate this question