How to Format JSON Online (and Fix the Errors)
Pretty-print in one click — and the three mistakes behind almost every 'Unexpected token'.
Paste your JSON into a browser-based JSON formatter and click Format — it indents the structure and reports the exact position of any syntax error. If it won't parse, the cause is almost always one of three things: a trailing comma, single quotes instead of double, or an unescaped newline inside a string. All three are valid JavaScript and invalid JSON, which is why they're so easy to write by accident.
Last updated 17 July 2026 IST · Maintained by SnoopTool, a free online tools website with 165+ browser-based utilities.| Broken | Error you'll see | Fix |
|---|---|---|
{"a": 1,} | Unexpected token } | Remove the trailing comma |
{'a': 1} | Unexpected token ' | Use double quotes: {"a": 1} |
{"a": "line1
line2"} | Unterminated string | Escape it: \n |
{"a": undefined} | Unexpected token u | Use null -- JSON has no undefined |
{a: 1} | Unexpected token a | Keys must be quoted strings |
{"a": 01} | Unexpected number | No leading zeros: use 1 |
Why valid JavaScript is often invalid JSON
This is the root of the confusion. JSON looks like a JavaScript object literal, so people assume anything JavaScript accepts, JSON accepts. It doesn't — JSON is a strict subset.
JavaScript happily takes {a: 1, b: 'two',}: unquoted keys, single quotes, trailing comma. JSON rejects all three. If you're copying an object out of your editor and pasting it as JSON, expect exactly these failures.
The other direction bites too: JSON has no undefined, no functions, no comments and no NaN. JSON.stringify() silently drops keys whose value is undefined or a function — a real source of “my field disappeared” bugs.
Reading error positions properly
“Unexpected token } at position 47” is more helpful than it looks, but you have to read it correctly: the parser reports where it gave up, not where you made the mistake.
With a trailing comma, the comma at position 46 is legal — the parser expects another key to follow. It only fails at position 47 when it finds } instead. So always look at the character before the reported position. That single habit resolves most JSON debugging.
Don't paste production JSON into a random site
The JSON you most need to format is usually the JSON you least want to leak — an API response with a bearer token, a webhook payload with customer emails, a config file with database credentials.
Most “online JSON formatter” sites POST your text to their backend. You've now put secrets in a third party's logs, and rotating that credential is the only clean remedy.
Client-side formatters use the browser's own JSON.parse() and never transmit anything. Verify it in 10 seconds: open DevTools → Network, click Format, and watch. No request means genuinely local.
Tools used in this guide
Frequently asked questions
How do I fix 'Unexpected token' in JSON?
Look at the character before the reported position — the parser reports where it gave up, not where the mistake is. The three usual causes are a trailing comma after the last item, single quotes instead of double quotes, and an unescaped newline inside a string. All three are legal JavaScript but illegal JSON, which is why they slip in so easily.
Why is my JavaScript object not valid JSON?
JSON is a strict subset of JavaScript syntax. JavaScript allows unquoted keys ({a: 1}), single quotes, and trailing commas; JSON allows none of them. JSON also has no undefined, no functions, no comments and no NaN. If you're pasting an object literal from your editor, those differences are almost certainly what's failing.
Can JSON have comments?
No — the specification excludes them deliberately, because parsers had begun using comments to carry directives, which broke interoperability. Common workarounds are a "_comment" key, or JSON5/JSONC in config files, though neither is standard JSON and strict parsers will reject them. If a tool rejects your config file, comments are a prime suspect.
Is it safe to format JSON online?
Only with a client-side formatter. Server-side tools receive your JSON and may log it — a genuine risk when the payload holds bearer tokens, credentials or customer data. SnoopTool's JSON Formatter uses your browser's native JSON.parse(), so nothing is transmitted. Confirm any tool by watching the DevTools Network tab while you click Format.
Need a tool we don't have yet?
Tell us what you're trying to do. We build the most-requested tools first — every SnoopTool utility is free, runs in your browser, and needs no sign-up.