Read JSON arrays, objects and scalar values
An API returns {"ports":[{"name":"Gi1","up":false},{"name":"Gi2","up":true}]}. Which value describes the operational flag of the second port?
Read JSON arrays, objects and scalar values
The serialization lesson distinguishes JSON’s scalar values from objects and arrays.
Work through the decision
An API returns {"ports":[{"name":"Gi1","up":false},{"name":"Gi2","up":true}]}. Which value describes the operational flag of the second port?
Check your reasoning
Read the ports array at index 1 and then the up property. Its value is the Boolean true. The quoted text "true" would be a string with a different type, and the index would change if the array order changed.
Interpret the evidence
- Array
- An ordered sequence is written in square brackets; an index selects an element.
- Object
- An object uses braces and maps string member names to values.
- Boolean
- The unquoted literals true and false represent logical values.
- String
- A quoted sequence of characters remains a string even when it looks numeric.
Practice the guide skills
- Read an interface name from an object nested in an array. Distinguish quoted numeric strings, numbers, Boolean values and null.
- Compare an empty collection with a missing property, then identify the effect of reordering the array on an index-based lookup.
Official objectives for this lesson
Distinguish a missing value from an empty collection
These are two different API responses to an inventory read.
{"device":"edge-1","neighbors":[]}
{"device":"edge-2"}
The first payload explicitly supplies an empty neighbor list. The second omits the field. Check the API contract before concluding the second device has no neighbors.
Related lesson · Choose a measurement that can settle the diagnosis
Read JSON arrays, objects and scalar values quiz
Answer 3 questions. Check each answer for an explanation.