What is JSON, and why do formatting and validation matter?
JSON is the default data interchange format of modern APIs and configuration files. The same document can be easy to read or cheap to transmit—formatting and minifying trade one goal for the other while the meaning stays identical.
What is JSON?
JSON (JavaScript Object Notation) is a text format for structured data
built from objects, arrays, strings, numbers, booleans, and
null. Despite its JavaScript roots, virtually every language
can read and write it.
A JSON document is valid if it parses according to the grammar. Trailing commas, single quotes, comments, and unquoted keys—all common in JavaScript—are syntax errors in strict JSON.
Formatting vs minifying
Same data, different audiences.
Format (pretty print)
Indented output is easier to review in code review, logs you read, and fixtures you maintain. Use two or four space indentation for consistency with your project.
Minify
Whitespace-insignificant output is smaller and faster to transfer or store. Minified JSON belongs in API responses, caches, and build artifacts—not files people edit.
Validate before shipping
A single stray comma breaks parsers downstream. Validating catches those errors before they reach an API client or a deployment.
Common JSON pitfalls
| Mistake | Example | Why it fails |
|---|---|---|
| Trailing comma | {"a": 1,} | The grammar forbids a comma before the closing brace. |
| Single quotes | {name: 'ada'} | Strings must use double quotation marks. |
| Unquoted keys | {name: "ada"} | Object keys must be quoted strings. |
| Comments | {// note
"a": 1} | Strict JSON has no comment syntax; use a sidecar field instead. |