What Is JSON and How Web Apps Exchange Data
Basics4 minInnovialabs editorial team
In short
JSON is a text format for structured data — objects, arrays, strings, numbers, true/false and null; frontends and backends use it to exchange data over HTTP with the Content-Type: application/json header.
JSON in a nutshell
JSON (JavaScript Object Notation) is a text format for transferring data. It looks like a JavaScript object, but it is just a string that almost any language can read: Python, PHP, Go, Java, C#.
When an online store shows a product list, the browser most often receives it from the server as JSON:
{
"id": 42,
"name": "Backpack",
"price": 349000,
"inStock": true,
"tags": ["school", "sport"],
"discount": null
}
Syntax and data types
JSON has only six types:
| Type | Example |
|---|---|
| string | "Tashkent" |
| number | 42, 3.14, -1e3 |
| boolean | true, false |
| null | null |
| array | [1, 2, 3] |
| object | {"key": "value"} |
Strict rules that set JSON apart from JavaScript:
- Keys use double quotes only:
{"name": "Ali"}, not{name: 'Ali'}. - Strings use double quotes only.
- No trailing commas after the last item.
- No comments.
- No
undefined, functions, dates orNaN. Dates are sent as strings, usually in ISO 8601:"2026-03-15T10:00:00Z".
How frontend and backend exchange JSON
The usual cycle:
- The frontend turns an object into a string:
JSON.stringify(). - It sends the string in the HTTP request body with the
Content-Type: application/jsonheader. - The server parses the string back into an object, processes it and replies with JSON too.
- The frontend parses the response:
response.json()orJSON.parse().
const res = await fetch('/api/orders', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ productId: 42, qty: 2 }),
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
const order = await res.json();
On an Express server one line, app.use(express.json()), does the same job: it reads request bodies with the right header and puts the result into req.body.
Common parsing errors
Unexpected token < in JSON— HTML arrived instead of JSON. Usually a 404 or 500 error page, a wrong API URL, or a redirect to a login page. Check the Network tab in DevTools.Unexpected end of JSON input— an empty response, such as status 204, or a truncated body. Do not callres.json()when there is no body.- Single quotes or a trailing comma — the JSON was built by hand with string concatenation. Always use
JSON.stringify. - The server does not see the request body — the
Content-Type: application/jsonheader or the parsing middleware is missing. - Large numbers lose precision — numbers above
Number.MAX_SAFE_INTEGERget rounded in JavaScript. Send large IDs as strings. - Dates arrive as strings — that is expected. Convert them to
Datewhere you need them.
A good habit is to check res.ok and the response Content-Type before parsing, and to validate incoming data on the server against a schema.
JSON vs XML vs form data
| JSON | XML | form data | |
|---|---|---|---|
| Where you see it | REST APIs, configs, mobile apps | legacy enterprise systems, SOAP, banking and government integrations | HTML forms, file uploads |
| Readability | high | lower, lots of tags | key-value pairs |
| Nested structures | natural | yes | awkward |
| Files | only via base64 | only via base64 | native through multipart |
| Parsing in the browser | JSON.parse | DOMParser | FormData |
How to choose:
- Regular API — JSON.
- File uploads —
multipart/form-data, with metadata in a neighboring field. - Integration with a legacy system that only speaks XML — XML, there is no choice.