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

Common errors and what they mean

Error messageLikely cause
Unexpected token } in JSON at position NTrailing comma before a closing brace/bracket
Unexpected end of JSON inputMissing closing brace/bracket, often from truncated data
Unexpected token u in JSON at position 0Trying to parse undefined or an empty response body
Unexpected non-whitespace character after JSONExtra data after the JSON value, like a stray comma or duplicate object

Debugging workflow

  1. 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.
  2. 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.
  3. 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.

Sources and further reading