JSON is the dominant data-interchange format on the modern web. It is simple on the surface — a handful of primitive types, objects with string keys, and arrays — but its strictness catches developers out daily. This guide reviews the structure, the syntax pitfalls that fail validation, when to format and when to minify, and the looser variants you will occasionally meet.

JSON structure

Every JSON document is either an object (wrapped in { } with comma-separated key–value pairs) or an array (wrapped in [ ] with comma-separated values). Values are strings (double-quoted), numbers, booleans (true/false), null, objects, or arrays. Keys must always be strings in double quotes — not single quotes, not bare identifiers.

Syntax errors that cost hours

Pretty-print vs minify

Pretty-printed JSON is for humans: indentation and line breaks help readers spot structure and compare values. Use it in configuration files, documentation, and debug logs. Minified JSON is for machines: everything on one line, no whitespace, smallest possible payload. Use it when the JSON travels over a network or is stored at scale. Most tools can flip between the two with one call (JSON.stringify(obj, null, 2) to pretty, JSON.stringify(obj) to minify).

JSON5 and JSONC

When you need comments and trailing commas, there are two common supersets. JSON5 allows single-quoted strings, unquoted keys, comments, trailing commas, hex numbers, and multi-line strings. JSONC — used by VS Code — is stricter: it only adds comments on top of plain JSON. Neither is universally parsed; convert to strict JSON before sending over the wire.

Size and performance

Minifying typical human-formatted JSON cuts its size by 15–30%. gzip compression flattens that difference considerably, so for HTTP-served JSON, gzip usually beats minification. For localStorage, IndexedDB, and bandwidth-constrained mobile payloads, minification still matters — every byte counts.

Validation as a habit

When a system rejects your JSON, paste it into a validator before editing. Nine out of ten parse errors are an unnoticed trailing comma, an accidental single quote, or a stray control character. A validator pinpoints the exact line and column, saving the half-hour of eyeballing you would otherwise spend.