200-301 Question 502
Select 3You are troubleshooting an API response from a web service that returns data in JSON format. The response includes the following snippet:
{ "device": { "hostname": "router1", "interfaces": [ {"name": "GigabitEthernet0/1", "status": "up"}, {"name": "GigabitEthernet0/2", "status": "down"} ] } }
Which of the following statements correctly identify components of the JSON data?
- A
"device" is a JSON object.
- B
"interfaces" is an array containing JSON objects.
- C
"status" is a key in the "interfaces" objects and has a value of type boolean.
- D
"hostname" is a key in the "device" object and its value is a string.
Show answer and explanation
Correct answers: A, B, D
Explanation
JSON data is structured with key-value pairs. Objects are enclosed in curly braces {}, arrays are enclosed in square brackets [], and values can be strings, numbers, booleans, null, objects, or arrays. Analyzing the structure of the provided JSON snippet, the correct answers identify the components accurately.
- A. Correct.
"device" is a JSON object because it contains key-value pairs enclosed in curly braces {}.
- B. Correct.
"interfaces" is an array because it is a list of items enclosed in square brackets []. Each item in the array is a JSON object.
- C. Incorrect.
"status" is a key in the "interfaces" objects, but its value is a string (e.g., "up" or "down"), not a boolean.
- D. Correct.
"hostname" is a key in the "device" object, and its value is indeed a string ("router1").