Where JSON is stricter than a JS object literal

JSON requires double-quoted property names and string values. It does not allow comments, trailing commas, undefined, functions, NaN or Infinity. JSON.parse() also rejects extra characters before or after the single top-level value. JavaScript object literals permit several of those features, which is why copied code may fail as JSON.

RULE βœ— INVALID βœ“ VALID Object keys name: "name": String values 'Ada' "Ada" Trailing commas ["a","b",] ["a","b"] Comments // a note (not allowed at all) JSON.parse() enforces all four, and the error message tells you the exact line and column that broke.

Why pretty-printing matters

An API response or a minified config file is usually returned as a single unbroken line; technically valid, but unreadable the moment you need to check a nested value or compare it against something else. Pretty-printing (adding consistent indentation and line breaks) doesn't change the data at all, it re-serializes the same parsed structure with whitespace a human can scan.

When to minify instead

Minifying does the opposite: it strips every non-essential space, so the same data takes less room. That matters when you're pasting JSON somewhere with a character limit, storing it compactly, or sending it over a network where every byte counts; none of which benefit from indentation that a machine doesn't need.

Common JSON syntax errors and what causes them

  • Trailing comma; leaving a comma after the last property or array item, a habit carried over from JavaScript (where it's harmless) or from editing a list and forgetting to remove the old separator.
  • Single-quoted strings; copying a JavaScript object literal directly, where single and double quotes are interchangeable; JSON only accepts double quotes.
  • Unquoted keys; same source: JavaScript allows bare identifier keys like name:, JSON requires "name":.
  • Mismatched or missing brackets; an extra or missing {, }, [, or ], usually from manually editing nested data by hand.
  • A missing comma between properties; easy to miss when reformatting JSON by hand instead of letting a formatter do it.

Parsing and formatting details

Strict JSON has no comments. JSON5 and JSONC add conveniences through separate syntaxes, and a standard JSON parser may reject them.

Member order generally should not carry meaning in a JSON object, but consumers, signatures, snapshots and text diffs can still depend on serialization order. Sorting keys is a transformation and may be inappropriate for signed or order-sensitive workflows.

Why does my JSON.parse error just say "position 45" instead of a line number? That's how V8 (Chrome's JavaScript engine) reports it; a formatter can convert that character offset into a line and column by counting newlines up to that position, which is exactly what a helpful error message should show instead.

Format your JSON

Orisod’s JSON Formatter validates, indents, minifies and optionally sorts keys in your browser. Review transformations carefully when exact serialization or signatures matter.

Format JSON β†’

Most "JSON.parse unexpected token" errors come down to one of the same handful of causes; a stray trailing comma, a copy-pasted single quote, or an unquoted key. Once you know the short list of rules, the fix is usually a five-second read of the error message away.