How to Read a JSON API Response (Beginner Guide)

How to Read a JSON API Response (Beginner Guide)

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.

Open the JSON Formatter

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

TypeLooks likeExample
Object{ "key": value }"customer": { ... }
Array[ value, value ]"orders": [ ... ]
StringText in double quotes"Hassan Ali"
NumberNo quotes2500
Booleantrue or false"paid": true
Nullnull"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:

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 wantPath
Customer namedata.customer.name
First order totaldata.orders[0].total
Second order paid?data.orders[1].paid
Current pagemeta.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

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.

Format an API response

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

← All guides