Common JSON Errors and How to Fix Them

Common JSON Errors and How to Fix Them

Most JSON errors come from ten slips: trailing commas, single quotes, unquoted keys, comments, unescaped quotes, raw line breaks, missing commas, unclosed brackets, undefined/NaN values and numbers with leading zeros. Paste your JSON into the free JSON Validator to find the exact line, then fix it with the table below.

Common JSON Errors and How to Fix Them

10 JSON errors and fixes

10 JSON errors and fixes
ErrorWrongRight
Trailing comma{"a": 1,}{"a": 1}
Single quotes{'a': 'x'}{"a": "x"}
Unquoted keys{a: 1}{"a": 1}
Comments{"a": 1 /* note */}{"a": 1}
Unescaped quote inside text{"q": "He said "hi""}{"q": "He said \"hi\""}
Raw line break in a string"line one
line two"
"line one\nline two"
Missing comma{"a": 1 "b": 2}{"a": 1, "b": 2}
Unclosed bracket{"list": [1, 2}{"list": [1, 2]}
undefined / NaN{"a": undefined}{"a": null}
Leading zeros{"pin": 0123}{"pin": "0123"}

Debugging steps

Debugging steps
  1. Paste the JSON into the JSON Validator.
  2. Go to the line it reports – the real mistake is often on the line before.
  3. Fix it using the table above.
  4. Format the result with the JSON Formatter to spot remaining problems.
  5. Validate again until it passes.

Why these mistakes happen

Why these mistakes happen
  • Trailing comma: Remove the comma after the last item in an object or array.
  • Single quotes: JSON only accepts double quotes for keys and strings.
  • Unquoted keys: Wrap every key in double quotes.
  • Comments: Delete comments – JSON has no comment syntax.
  • Unescaped quote inside text: Escape inner double quotes with a backslash.

Avoid errors in the first place

  • Generate JSON with your language's built-in encoder (JSON.stringify, json_encode, json.dumps) instead of writing it by hand.
  • Use an editor with JSON syntax highlighting.
  • Validate API responses in development before parsing them.
Try the free JSON Validator now

Open the JSON Validator on pdfseotools.com – free, no sign-up and it works on any device.

Open JSON Validator →

Domande frequenti

How do I find the exact error?

🧑‍💻 Paste the JSON into the JSON Validator. It points to the problem, usually with a line number.

Why does my API say "Unexpected token"?

The response is not valid JSON – often an HTML error page, a trailing comma or text before the opening brace.

Can I put comments in package.json or other config files?

Not in strict JSON files like package.json. Some tools accept JSONC or JSON5 – only use comments where the tool documents support.

Why do big numbers change after parsing?

JavaScript cannot store integers above 2^53 exactly. Send large IDs as strings.

Is JSON case-sensitive?

Yes. "Name" and "name" are different keys, and true/false/null must be lower case.

Are the tools in this guide free to use?

Yes. The tools in this guide on pdfseotools.com are free to use – no sign-up, no watermark and no hidden charges for everyday tasks.

Summary

Validate, jump to the reported line, check the line before, fix, repeat. Use the JSON Validator and the other free developer tools.


Condividi sui social media: