How to Read a JSON API Response (Beginner Guide)
Published November 25, 2026 · 7 min read
A JSON API response looks scary when it arrives as one long line. It is built from just two things:
objects in { } that hold named values, and arrays in
[ ] that hold lists. Once you can spot those two, you can find any value with a simple path
like data.orders[0].total.
First step, always: paste the response into the JSON Formatter so it is indented and easy to read.
Step 1: Format it
Raw response:
{"status":"success","data":{"customer":{"id":42,"name":"Hassan Ali","email":"hassan@example.com"},"orders":[{"id":1001,"total":2500,"paid":true},{"id":1002,"total":1200,"paid":false}]},"meta":{"page":1,"per_page":20}}
Formatted:
{
"status": "success",
"data": {
"customer": {
"id": 42,
"name": "Hassan Ali",
"email": "hassan@example.com"
},
"orders": [
{ "id": 1001, "total": 2500, "paid": true },
{ "id": 1002, "total": 1200, "paid": false }
]
},
"meta": { "page": 1, "per_page": 20 }
}
Now the structure is clear. If the formatter reports an error instead, the response isn't valid JSON: see Unexpected Token in JSON.
Step 2: Know the six value types
| Type | Looks like | Example |
|---|---|---|
| Object | { "key": value } | "customer": { ... } |
| Array | [ value, value ] | "orders": [ ... ] |
| String | Text in double quotes | "Hassan Ali" |
| Number | No quotes | 2500 |
| Boolean | true or false | "paid": true |
| Null | null | "phone": null |
A common bug: "2500" in quotes is a string, not a number. In JavaScript,
"2500" + 100 gives "2500100", joining text instead of adding. Convert it with
Number() first.
Step 3: Read the top level
Most APIs wrap the useful part. Look at the top-level keys first:
statusorsuccess: did the request work?dataorresults: the actual contentmetaorpagination: page number, totals, next page linkerrorormessage: what went wrong, if it failed
Step 4: Follow the path to a value
Use a dot for each object key and [n] for each array position. Arrays start at 0.
| You want | Path |
|---|---|
| Customer name | data.customer.name |
| First order total | data.orders[0].total |
| Second order paid? | data.orders[1].paid |
| Current page | meta.page |
The same path in code:
// JavaScript
const total = response.data.orders[0].total;
# Python
total = response["data"]["orders"][0]["total"]
// PHP (after json_decode($body, true))
$total = $response['data']['orders'][0]['total'];
// or with Laravel's helper
$total = data_get($response, 'data.orders.0.total');
Step 5: Loop through arrays
When a key holds a list, loop over it instead of using fixed positions:
response.data.orders.forEach(order => {
console.log(order.id, order.total);
});
Common beginner mistakes
- Reading a key that is missing. Check it exists first, or use optional chaining:
response.data?.customer?.name. - Forgetting arrays start at 0. The first item is
[0], not[1]. - Treating an object like an array.
data.customer[0]givesundefinedbecausecustomeris an object. - Parsing twice.
await response.json()already returns an object. Don't callJSON.parseon it again.
Wondering why APIs use JSON and not XML or YAML? See JSON vs XML vs YAML. Asking an AI assistant about a response? How to Share Code With ChatGPT or Claude covers what to include. More formatting tips are in How to Format, Validate and Fix JSON.
Paste a one-line response and get it indented, so you can see the objects, arrays and paths at a glance.
Frequently asked questions
What is the difference between { } and [ ] in JSON?
Curly braces hold an object with named keys. Square brackets hold an ordered list.
How do I make JSON readable?
Paste it into a JSON formatter, or use your browser’s Network tab, which shows a tree view.
How do I share an API response for help?
Remove tokens and personal data first, then share it with a code share link.
Why do I get undefined when reading a value?
The path is wrong or the key is missing. Log the whole response and check the path step by step.
Related articles
"Unexpected Token in JSON": What It Means and How to Fix It
What JSON.parse errors mean in Chrome, Firefox, Python and PHP, the 7 most common causes from trailing commas to HTML responses, and how to find the exact line.
Read More →JSON vs XML vs YAML: Differences With Examples
The same data in JSON, XML and YAML side by side, a comparison table, YAML gotchas like the Norway problem, and when to use each format.
Read More →How to Share Code With ChatGPT or Claude (and Get Better Answers)
Paste, upload or link code for ChatGPT and Claude the right way: keeping formatting, how much code to include, prompts that get useful answers, and what to remove before sharing.
Read More →