JSON (JavaScript Object Notation) is the lingua franca of the modern web. It is how browsers talk to servers, how APIs return data, and how configuration is stored across countless tools. Despite its simplicity, small mistakes cause big headaches.
The building blocks
JSON has just six value types: strings, numbers, booleans, null, arrays and objects. Objects are unordered key/value pairs wrapped in braces; arrays are ordered lists wrapped in brackets.
{
"name": "Ada",
"active": true,
"skills": ["math", "code"],
"manager": null
}The mistakes that break parsers
- Trailing commas — valid in JavaScript, invalid in JSON.
- Single quotes — JSON strings must use double quotes.
- Unquoted keys — every key must be a quoted string.
- Comments — JSON has no comment syntax.
Formatting for humans and machines
Pretty-print JSON when you are reading it, and minify it when you are shipping it. Indentation makes structure obvious during debugging, while minification removes whitespace to shrink payloads in production.
When JSON is not the right format
JSON wins for APIs, configuration and anything nested. But it is not the best tool for every job: CSV is lighter for flat tabular exports, YAML is friendlier for hand-edited config you want commented, and XML is still expected by feeds and legacy SOAP services. Choosing by data shape — not by habit — keeps every format doing what it is good at.
Parsing safely in JavaScript
try {
const data = JSON.parse(input)
// …use data
} catch (err) {
console.error(err.message) // line & column of the parse error
}JSON.parse throws on the first syntax problem and its message names the offending position — which is exactly why a formatter that pinpoints the line is so useful when a payload arrives from a third party.
JSON in the API lifecycle
APIs mostly speak JSON, and the format your tooling mistrusts will cost you debugging cycles. A response that “looks fine” but fails downstream usually fails for three reasons: a trailing comma, a missing comma between objects, or an unexpected nesting depth in array-of-objects data. Validating the payload before it reaches the consumer, and formatting before you read it, keeps every layer of the pipeline working from the same, verified document rather than from uncertain text.
- Formatted JSON is the debugging format; minified JSON is the transport format.
- Keep payloads validated — a parser error deep in a microservice is the most expensive kind.
- Nested applications often have cleaner surface if you break them out — but that is an API design call, not a format one.