JSON Explained: Syntax, Common Errors, and How to Debug Them
Published June 2, 2026
Prepared by Innealan Editorial
Interested in advertising in this spot?
Contact us for sponsorship options
JSON (JavaScript Object Notation) is a common format for APIs, configuration files, and data interchange on the web. It is easy to read until a small syntax mistake produces a cryptic “Unexpected token” error.
The core syntax rules
- Keys must be double-quoted strings.
{name: "Alice"}is invalid; it must be{"name": "Alice"}. Single quotes are never allowed, for keys or values. - No trailing commas.
["a", "b",]fails in strict JSON, even though it’s valid in JavaScript object/array literals. - No comments. JSON has no
//or/* */syntax. If you need comments, you’re probably looking for JSON5 or JSONC, not JSON. - Numbers can’t have leading zeros or a trailing decimal point.
01and1.are both invalid; use1and1.0. - Only these value types exist: string, number, boolean,
null, object, and array.undefined,NaN, andInfinityare not valid JSON values.
Common errors and what they mean
| Error message | Likely cause |
|---|---|
Unexpected token } in JSON at position N | Trailing comma before a closing brace/bracket |
Unexpected end of JSON input | Missing closing brace/bracket, often from truncated data |
Unexpected token u in JSON at position 0 | Trying to parse undefined or an empty response body |
Unexpected non-whitespace character after JSON | Extra data after the JSON value, like a stray comma or duplicate object |
Debugging workflow
- Isolate the smallest failing snippet. If you’re debugging a huge API response, binary-search by deleting half the content until the error disappears, then narrow in.
- Use a validator that reports position, not just “invalid”. Position numbers let you count characters (or use your editor’s “go to offset”) to find the exact spot.
- Watch for encoding issues. A BOM (byte-order mark) at the start of a file, or smart quotes copy-pasted from a word processor, will both break parsing silently.
For example, when {"enabled": true,} fails, remove the comma before }. Do not change true to "true"; the boolean value was valid already. Fix the token named in the parser error, then validate again.
Our JSON Formatter & Validator highlights the exact error message from your browser’s native JSON parser, and lets you pretty-print or minify valid JSON in one click. It’s all client-side, so nothing you paste ever leaves your browser.