How to fix invalid JSON

Open the JSON Formatter & Validator

JSON is strict. A single trailing comma, a single quote or a comment makes the whole document invalid, and the error message often points at the character after the real mistake. Paste your JSON into the JSON Formatter & Validator and press Format: valid JSON comes back neatly indented, and invalid JSON shows the browser's error message with the position of the problem.

The validator runs entirely in your browser using the browser's own JSON parser, so your data is not sent to our server. It tells you where the JSON breaks; it does not repair it for you. The table of causes below covers almost every error you will see.

The 8 mistakes behind most invalid JSON

Messages below are the ones Chrome and Edge show; Firefox and Safari word them differently but point at the same place. Position counts characters from 0.

  • Trailing comma, as in {"a":1,} — "Expected double-quoted property name". Remove the comma after the last item in an object or array.
  • Single quotes, as in {'a':1} — "Expected property name or '}'". JSON only allows double quotes around keys and text.
  • Keys without quotes, as in {a:1} — the same "Expected property name or '}'" error. Write {"a":1}.
  • Comments such as // or /* */ — "Expected ',' or '}' after property value". JSON has no comments; delete them.
  • Missing comma between two items — also "Expected ',' or '}' after property value", pointing at the start of the second item.
  • NaN, undefined, Infinity or a function — "Unexpected token". Use null, a number or a string instead.
  • A real line break or tab inside a string — "Bad control character in string literal". Write it as \n or \t.
  • Curly “smart” quotes pasted from a word processor or chat app — "Expected property name or '}'". Replace them with straight double quotes.

Two objects one after the other, {"a":1}{"b":2}, give "Unexpected non-whitespace character after JSON". Wrap them in an array, [{"a":1},{"b":2}], or keep one per line if your system expects JSON Lines.

Reading the position in the error

"At position 7" means the parser gave up at the eighth character. The real mistake is usually just before that point: in {"a":1,} position 7 is the closing brace, and the fault is the comma before it. Newer versions of Chrome also show a line and column, which is easier to use on long files. Formatting a large file first, even partly, makes the line number much more useful.

Two things that are valid but can still surprise you

  • Very large numbers lose precision. Browsers store numbers as 64-bit floating point, so an ID like 12345678901234567890 comes back from formatting as 12345678901234567000. If you work with long IDs, keep them as strings in the JSON.
  • Duplicate keys are allowed by the parser, but only the last one survives. {"a":1,"a":2} formats as {"a":2} with no warning.

Privacy

Formatting and validation run in your browser tab. We do not receive or store the JSON you paste. Even so, avoid pasting live passwords or API keys into any website you do not control.

Find and fix a JSON error

  1. Paste the JSON into the JSON Formatter & Validator and press Format.
  2. If it says Invalid JSON, note the position (or line and column) in the message.
  3. Look at the character just before that point, fix it using the list above, and press Format again until the output appears.

Related tools

FAQ

What does "Unexpected token" mean in JSON?
The parser found a character that cannot appear at that point, such as N from NaN, a single quote, or the letter at the start of an unquoted key. Look at the position in the message and the character just before it.
Are trailing commas allowed in JSON?
No. A comma after the last item in an object or array makes the JSON invalid, even though JavaScript code allows it.
Can JSON have comments?
No. Standard JSON has no comments. Remove // and /* */ lines before parsing.
Does the validator fix my JSON automatically?
No. It shows where the JSON breaks and pretty-prints it once it is valid. You make the fix.
Why did a long number change after formatting?
Browsers store numbers as 64-bit floating point, which is exact only up to 9,007,199,254,740,991. Keep longer IDs as strings.
Is my JSON uploaded?
No. The formatter runs in your browser.