API Bouncer

Buy me a coffee

JSON for Beginners: Understanding API Data

Every API guide tells you "the API returns JSON," but what exactly is JSON? If you're new to programming, JSON can look like a confusing wall of brackets and quotes. Let's break it down in plain English.

What is JSON?

JSON stands for JavaScript Object Notation. It's a text format for storing and transmitting structured data. Despite the name, JSON isn't just for JavaScript — every programming language can read and write it.

JSON has become the universal language of APIs. When you ask an API for data, it almost always responds with JSON.

JSON syntax in 5 minutes

JSON has only two structures: objects (curly braces) and arrays (square brackets).

Objects — key-value pairs

An object is a collection of named values, like a dictionary:

{ "name": "Pikachu", "type": "electric", "level": 25, "evolved": false }

Rules: Keys are always strings in double quotes. Values can be strings, numbers, booleans (true/false), null, arrays, or other objects.

Arrays — ordered lists

An array is an ordered list of values:

{ "team": ["Pikachu", "Charizard", "Blastoise"], "badges": 8, "items": [ { "name": "Potion", "quantity": 5 }, { "name": "Poke Ball", "quantity": 12 } ] }

Arrays use square brackets and can contain any type of value — including other objects and arrays.

Data types

JSON supports six data types:

Reading JSON from an API

When you call an API, you get a JSON string back. In JavaScript, you convert it to a usable object with .json():

const response = await fetch('https://pokeapi.co/api/v2/pokemon/pikachu'); const data = await response.json(); // Now 'data' is a JavaScript object you can work with console.log(data.name); // "pikachu" console.log(data.height); // 4 console.log(data.types[0].type.name); // "electric"

Navigating nested JSON

Real API responses are often deeply nested. Here's a simplified weather API response:

{ "location": { "city": "New York", "country": "US", "coordinates": { "lat": 40.71, "lon": -74.01 } }, "current": { "temperature": 18.5, "conditions": "Partly cloudy", "wind": { "speed": 12.3, "direction": "NW" } }, "forecast": [ { "day": "Monday", "high": 21, "low": 14 }, { "day": "Tuesday", "high": 19, "low": 12 } ] }

To access the wind speed: data.current.wind.speed

To get Tuesday's high: data.forecast[1].high

Use dot notation for object properties and bracket notation with an index for array elements.

Common JSON mistakes

Useful tools

Practice reading JSON

The best way to get comfortable with JSON is to read real API responses. Try these in your browser console:

// A simple response fetch('https://dog.ceo/api/breeds/image/random').then(r=>r.json()).then(console.log); // A complex nested response fetch('https://pokeapi.co/api/v2/pokemon/1').then(r=>r.json()).then(console.log); // An array response fetch('https://restcountries.com/v3.1/name/japan').then(r=>r.json()).then(console.log);

Expand the objects in the console, click through the nested structures, and trace the paths to specific values. Within an hour, reading JSON will feel natural.