200-301 Question 505
Select 3You are troubleshooting an API response from a web server that provides JSON-encoded data. The response contains the following JSON object:
{ "device": { "hostname": "Router1", "interfaces": [ {"name": "GigabitEthernet0/1", "status": "up"}, {"name": "GigabitEthernet0/2", "status": "down"} ] } }
Which of the following statements about the JSON structure are correct?
- A
The value of the key 'hostname' is a string.
- B
The 'interfaces' key holds a JSON object.
- C
The JSON structure is invalid because it contains an array.
- D
The 'device' key holds another JSON object.
- E
Each item in the 'interfaces' array is a JSON object.
Show answer and explanation
Correct answers: A, D, E
Explanation
In JSON, data is represented in key-value pairs, with values being strings, numbers, objects, arrays, or other valid JSON types. The provided JSON structure is valid and follows the correct syntax. The key 'hostname' holds a string, 'device' holds a JSON object, and 'interfaces' is an array of JSON objects.
- A. Correct.
Correct. The value of 'hostname' is clearly a string, as it is enclosed in double quotes.
- B. Incorrect.
Incorrect. The 'interfaces' key holds an array, not a JSON object. Arrays in JSON are enclosed in square brackets.
- C. Incorrect.
Incorrect. The JSON structure is valid. Arrays are a standard data type in JSON and are properly used in this example.
- D. Correct.
Correct. The 'device' key holds another JSON object, as indicated by the curly braces enclosing its value.
- E. Correct.
Correct. Each item in the 'interfaces' array is a JSON object, as evidenced by the curly braces around the key-value pairs within the array.