Understanding JSON: structure, common errors and formatting
Published June 13, 2026
JSON — JavaScript Object Notation — has become the default way programs exchange structured data. Config files, API responses and saved settings are very often JSON, because it is readable by humans yet trivial for machines to parse. The format is small enough to learn in an afternoon, but its strictness surprises newcomers: rules that feel optional in everyday writing are mandatory here, and breaking one stops the whole document from loading.
The building blocks
JSON is built from just two container types and four basic values. Objects are wrapped in curly braces and hold key–value pairs, like {"name": "Budi", "age": 30}. Arrays are wrapped in square brackets and hold an ordered list, like [1, 2, 3]. Inside them you can place strings (always in double quotes), numbers, the literals true / false / null, and more objects or arrays nested to any depth.
The rules people break most
- Trailing commas are forbidden. A comma after the last item — [1, 2, 3,] — is valid in JavaScript but invalid JSON.
- Keys and strings need double quotes. Single quotes or unquoted keys both fail.
- Comments are not allowed. JSON has no // or /* */ — strip them before parsing.
- Numbers cannot have leading zeros or a trailing dot, and special characters in strings must be escaped with a backslash.
Reading a parser error
A message like "Unexpected token } at position 48" is more helpful than it looks. The position is a character offset into the text, so it points you near the break — usually a comma or quote a little before that spot, not necessarily at it. Because one early mistake often cascades, fix the first reported error and re-check; the later complaints frequently vanish on their own.
Minify or pretty-print?
The same JSON can be written compact on one line or indented across many. Minified JSON strips every optional space to make files smaller and faster to send — ideal for production APIs. Pretty-printed JSON adds indentation and line breaks so a human can scan the structure — ideal while debugging. The data is identical either way; only the whitespace changes. Our JSON formatter does both, validates as it goes, and never sends your data anywhere, so you can safely format payloads that contain private fields.