JSON (JavaScript Object Notation) is the lingua franca of modern APIs. Nearly every REST service you will encounter accepts and returns JSON, so reading and shaping it fluently is a core skill. In this lesson we cover JSON syntax, how it flows through requests and responses, and the conventions that separate clean API payloads from messy ones.
JSON has exactly six value types: strings, numbers, booleans, null, arrays, and objects. Keys must be double-quoted strings, and there are no comments or trailing commas.
{
"id": 314,
"title": "Wireless Mouse",
"price": 24.5,
"inStock": true,
"tags": ["electronics", "accessories"],
"warranty": null,
"dimensions": { "widthCm": 6.2, "lengthCm": 10.8 }
}Notably missing: dates, binary data, and undefined. Dates are conventionally sent as ISO 8601 strings like "2026-07-20T14:30:00Z", and binary data is either base64-encoded or, better, served from a separate URL.
When a client sends JSON, two things must happen: the body contains serialized JSON text, and the Content-Type header declares application/json so the server knows how to parse it. The server responds in kind, setting its own Content-Type on the way back.
In JavaScript the bridge between objects and JSON text is a pair of built-ins: JSON.stringify turns an object into a string for sending, and JSON.parse turns received text back into an object. Most frameworks do this for you: Express with express.json() middleware, and fetch with response.json().
Good API payloads follow a few widely shared conventions:
Watch out for these classics. Large integers: JavaScript numbers lose precision beyond 2^53, so 64-bit database IDs are often sent as strings. Floating-point money: send prices in minor units ("amountCents": 2450) or as strings to avoid rounding bugs. Parsing errors: a client sending invalid JSON should receive 400 Bad Request, not a 500 crash, so always handle parse failures. Character encoding: JSON is UTF-8 by default; do not fight it.
Imagine a weather API response designed with these rules:
{
"data": {
"city": "Mumbai",
"observedAt": "2026-07-20T09:00:00Z",
"temperatureC": 29.4,
"conditions": ["humid", "cloudy"]
},
"meta": { "source": "station-114", "units": "metric" }
}A mobile app, a dashboard, and a partner integration can all consume this without special cases, which is exactly the point of consistent JSON design.
Next up: HTTP Headers and Content Negotiation, where metadata does the heavy lifting.