JSON parse error: common causes and quick fixes

A JSON parse error usually means the text is almost JSON, but one character or rule is wrong. Start by validating the same text that failed, then fix the earliest syntax problem before formatting it.

Fast check

If a request body, config file, package file, or log payload will not parse, paste the smallest failing snippet into the JSON Validator. Once it passes, use the JSON Formatter only for readability or minification.

Common JSON parse errors

Error patternBroken JSONFix
Trailing comma{"name":"Sam",}{"name":"Sam"}
Single quotes{'name':'Sam'}{"name":"Sam"}
Unquoted key{name:"Sam"}{"name":"Sam"}
Comment inside JSON{"ok":true // note}Remove the comment before parsing.
JavaScript-only value{"count":undefined}Use null, a number, string, boolean, array, or object.
Raw newline in a string{"text":"line 1 [line break] line 2"}Use an escaped newline: {"text":"line 1\nline 2"}.
Missing close brace{"items":[1,2,3]{"items":[1,2,3]}

How to debug the error

  1. Copy the smallest snippet that still fails.
  2. Validate it before formatting it.
  3. Fix the first syntax problem, not every visible problem at once.
  4. Validate again, then format the cleaned JSON if you need a readable version.

What the error message may hide

Parser messages often point to where parsing finally failed, not where the real mistake started. A missing quote or comma can make the next line look wrong. If the payload came from logs, also check for copied prefixes, truncated output, or extra text before and after the JSON.

JSON is stricter than JavaScript objects

Many parse errors happen because the text is valid JavaScript object syntax but not valid JSON. JSON requires double quotes around object keys and string values, does not allow comments, and does not allow values such as undefined, NaN, or Infinity. MDN documents the common JSON.parse SyntaxError patterns.

FAQ

It means the parser could not turn the text into valid JSON. The cause is usually a syntax issue such as a trailing comma, single quotes, an unquoted key, a missing brace, or an invalid escape sequence.

Validate first when you see a parse error. Formatting is useful after the JSON parses cleanly; it will not reliably explain why broken JSON failed.

JSON is stricter than JavaScript object literals. JSON requires double-quoted object keys and string values, does not allow comments, and does not allow values like undefined, NaN, or Infinity.