Recognize the three shapes
An object maps quoted keys to values: { "id": 42 }.
An array holds ordered values: ["red", "blue"].
Values are strings, numbers, booleans, null, objects, or arrays.
A key belongs to the object whose braces contain it. An array position is identified by its zero-based index in most programming languages. Objects and arrays can contain each other, so a response can alternate between keys and indexes.
The root value is not required to be an object. A JSON document can start with an array, string, number, boolean, or null. Before assuming a path such as response.data, inspect the first level and confirm the API’s actual response shape. A root array is indexed directly, while a root scalar has no child keys to traverse.
Walk through a realistic response
This example uses fictional account and project data. Read the outermost keys first: requestId, data, and meta. The resource records sit under data; pagination information sits separately under meta.
{
"requestId": "req_7f31",
"data": {
"account": { "id": 42, "name": "Northwind Demo" },
"projects": [
{ "id": "p-1", "status": "active", "members": [{ "name": "Mina", "role": "owner" }] },
{ "id": "p-2", "status": "paused", "members": [] }
]
},
"meta": { "page": 1, "hasMore": false }
}data.account.nameThe account's display namedata.projects[0].idThe first project's identifierdata.projects[0].members[0].roleThe first member's role on project onemeta.hasMoreWhether another result page existsNavigate one segment at a time
For data.projects[0].members[0].role, open the root object and select data; then projects. The first array index is 0, then open that object's members array, select index 0, and read role. In JavaScript, the equivalent is response.data.projects[0].members[0].role.
Tree outline
root object
└─ data (object)
└─ projects (array)
├─ [0] (object)
│ └─ members (array)
│ └─ [0] (object) → role: "owner"
└─ [1] (object)Mistakes that make nested data confusing
Do not assume every array contains objects: this response's second project's members is an empty array. Check for null before traversing optional fields, and distinguish an absent key from a present key whose value is null. Also check the actual nesting: APIs often wrap records in data, but that convention is not universal.
Access the same path in code
After confirming the structure, your code can follow the same sequence. In JavaScript, response.data.projects[0].members[0].role works only if data, projects, and the first project exist, and members contains an element. For optional fields, optional chaining such as response.data?.projects?.[0]?.members?.[0]?.role prevents a property-access exception. It does not decide what your application should do when the result is undefined; that fallback remains a product or business rule.
Three similar-looking cases deserve different handling: a missing key, a key whose value is null, and an empty array. Missing means the producer did not include that property. Null means the property exists and explicitly has JSON’s null value. An empty array is a present collection with zero elements, so index [0] has no value. Check which state your API uses before adding defaults.
Property names are case-sensitive, so userID and userId are different keys. A path that works against one response can fail when an API version changes casing or moves a field. If you query nested data repeatedly, document the expected path in a test or schema and include examples for empty arrays, null values, and missing optional properties.
The JSON Viewer can show nested values as a collapsible tree. For a syntax refresher, see formatting JSON.