Ten Common JSON Errors, With the Exact Messages and Fixes

By Junaid Aslam. 6 min read. Updated .

A JSON parser is strict, and its error messages are short. The JSON Formatter shows the message the browser returns, unchanged, under a fixed Invalid JSON heading. That is enough to find most mistakes if you know what each message points at.

We put ten broken inputs through the page, three runs each, and then ran each fixed input again. Nine of the ten messages name a position or quote the input. Two different mistakes produce the same message, and one message points at a character you cannot see.

How the page reports a parse error

Paste the text, then click Format, Minify, or Validate. Parsing runs in a Web Worker. When it fails, the page shows a red box with the heading Invalid JSON and the parser's own message below it. The page does not rewrite the message or add a guessed location.

The message comes from JSON.parse in your browser, so the wording is the browser's, not the site's. The runs below used Chromium, and every message was identical in all three runs of the same input.

The ten cases

Broken inputMessage after Invalid JSONFix
{"a": 1,}Expected double-quoted property name in JSON at position 8 (line 1 column 9){"a": 1}
[1, 2, 3,]Unexpected token ']', "[1, 2, 3,]" is not valid JSON[1, 2, 3]
{'a': 1}Expected property name or '}' in JSON at position 1 (line 1 column 2){"a": 1}
{a: 1}Expected property name or '}' in JSON at position 1 (line 1 column 2){"a": 1}
{"a": 1 "b": 2}Expected ',' or '}' after property value in JSON at position 8 (line 1 column 9){"a": 1, "b": 2}
A literal line break inside a stringBad control character in string literal in JSON at position 18 (line 1 column 19)Escape it as \n
{"a": 1Expected ',' or '}' after property value in JSON at position 7 (line 1 column 8){"a": 1}
{"a": undefined}Unexpected token 'u', "{"a": undefined}" is not valid JSON{"a": null}
{"a": 1} // doneUnexpected non-whitespace character after JSON at position 9 (line 1 column 10){"a": 1}
A byte order mark, then {"a": 1}Unexpected token ' ', "{"a": 1}" is not valid JSON{"a": 1}
The first character inside the quotes in the last message is U+FEFF, the byte order mark. It looks like a space in the text. Remove the character, do not retype the quote.

Two pairs that look alike

Single quotes and an unquoted key both stop at position 1 with Expected property name or '}'. That is because a JSON object name must be a double-quoted string. Whether the first character is a quote or a letter, the parser sees a name it cannot accept.

A trailing comma and a missing comma both report position 8 on a similar input, but the messages differ. {"a": 1,} gets Expected double-quoted property name, because after a comma the parser expects another name. {"a": 1 "b": 2} gets Expected ',' or '}' after property value, because after a value the parser expects the object to close or a comma to follow.

That distinction is the fastest way to read these two messages. A complaint about a property name after position N means look just after the last comma. A complaint about a missing comma or brace means look just before the next thing.

What the position numbers mean

The number after position counts characters from zero. In {"a": 1,} the closing brace is at index 8, and that is the token that failed. The line and column values count from one, so the same spot reads line 1, column 9.

Not every message has a position. The three legacy-style messages (Unexpected token, Unexpected non-whitespace character after JSON) are shorter, and two of them quote the whole input instead. When there is no position, the quoted text and the message are the clue.

The fixes that are more than punctuation

Three of the ten cases are not a missing comma or quote, and each has a rule behind it.

  • undefined is not JSON. RFC 8259 allows exactly three literal names: false, null, and true, and says they must be lowercase. Use null when a value is absent, or omit the key.
  • Comments are not JSON. The same grammar has no production for // or /* */. Remove the comment, or put the note in a key that your reader ignores.
  • A literal line break inside a string is a control character. RFC 8259 requires the characters U+0000 through U+001F to be escaped. Write \n inside the string, not a real line break.
  • A byte order mark is not allowed in a JSON text. RFC 8259 says an implementation must not add one, and a parser may ignore it rather than fail. This parser does not ignore it, so the first token becomes an invisible character. Remove the mark in a text editor that can show it, or in a script.

Every fix, checked by the page

Each fixed input was pasted back into a fresh page and formatted three times. All thirty runs produced the same formatted output, with no error box:

Fixed inputFormatted outputRuns
{"a": 1}Three-line object, two-space indent3 of 3
[1, 2, 3]Three-item array, one item per line3 of 3
{"a": 1, "b": 2}Two keys, two-space indent3 of 3
{"note": "line one\nline two"}One key with an escaped newline3 of 3
{"a": null}One key with null3 of 3

The page also has Validate, which returns ✓ Valid JSON for a valid input instead of the formatted text. We used Format because it proves two things at once: the parse succeeded, and the output is what a reader would see.

A checklist before you click Format

  • Look at the character before the reported position, not only at the position itself. A stray comma often sits one place earlier.
  • Check quotes. Every name and string needs double quotes, and a single-quoted string fails the same way as a bare name.
  • Remove comments before parsing. A config file can keep them, a JSON file cannot.
  • Replace undefined, NaN, and Infinity. JSON has no literal for any of them.
  • If the input came from another program, check for a byte order mark at the start. It is invisible in most text boxes.
  • After a fix, run it again. A second error usually means the first fix moved the problem, not that the input is hopeless.

Tested on

2026-11-17, against commit 0a0a237 on a local production build (Next.js 14.2.35). Browser: Chromium 159.0.8154.6 through Playwright 1.65.1 on Node 24.20.0. Host: Windows 10 desktop. Each of the ten broken inputs ran three times in a fresh context, and each of the ten fixes ran three times, for 60 runs in total. Firefox and WebKit were not installed for this Playwright version, so this guide reports Chromium only.

Primary sources

Document sources and photo credits

This guide has no photos. The ten inputs are short strings written for this test, and the messages are copied from the page on the date above. No third-party file is used.

Related tools

  • JSON Formatter: format, minify, validate, query with JSONPath, and convert to CSV, YAML, or TOML.
  • JSON to Zod and Schema: infer a schema from a valid JSON sample.
  • CSV Cleaner: fix a CSV before you turn it into JSON.
  • Text Diff: compare a broken file with the fixed one and see the exact characters that changed.

Try it yourself

More guides