DevFormatLab
← Back to blog

Common JSON Errors and How to Fix Them

By DevFormatLab·8 min read
JSONDebuggingJavaScriptTutorial

JSON (JavaScript Object Notation) is everywhere — APIs, config files, NoSQL databases, data exchange. But when it breaks, the error messages can be cryptic. This guide walks through the most common JSON errors and exactly how to fix them.

1. SyntaxError: Unexpected token

This is the most common JSON error. It means the parser hit a character it didn't expect at that position.

Common causes:

  • Trailing commas: {"name": "Alice",} — that comma after "Alice" is invalid in JSON
  • Single quotes: JSON requires double quotes
  • Unquoted keys: JSON keys must be quoted
  • Comments: JSON doesn't support comments

How to fix:

Paste your JSON into our JSON Formatter — it will point you directly to the line and column where the error occurs.

2. SyntaxError: Unterminated string

A string literal wasn't closed properly. The parser reached the end of input while still looking for the closing quote.

How to fix:

Look at the position reported by the error. Our JSON Formatter will highlight the unterminated region.

3. SyntaxError: Unexpected end of JSON input

The parser reached the end of the file before the JSON structure was complete.

How to fix:

Count your opening and closing braces/brackets. A good strategy is to indent properly and then check that the indentation makes sense.

4. ReferenceError: xxx is not defined

This happens when you try to use JSON directly in JavaScript without quoting it as a string first.

5. Numbers with leading zeros

JSON doesn't allow leading zeros on numbers unless the number is exactly "0".

6. Invalid escape sequences

JSON only recognizes these escape sequences: backslash-quote, double-backslash, backslash-slash, backslash-b, backslash-f, backslash-n, backslash-r, backslash-t, and backslash-u followed by four hex digits. Anything else like backslash-e or backslash-x is invalid.

Pro Tips for Debugging JSON

  1. Use the formatter first — paste into our JSON Formatter to get precise line/column positions
  2. Work from the outside in — check the outermost structure closes properly before debugging inner objects
  3. Validate incrementally — if you have a large JSON file, remove sections and re-validate
  4. Compare against valid JSON — use JSON Diff to compare your malformed JSON against a known-good template

When JSON Validates But Still Doesn't Work

Sometimes JSON is syntactically valid but semantically wrong. For example string vs number mismatch, null vs undefined, case sensitivity.


All tools mentioned in this article run 100% in your browser — your data never leaves your device. Happy debugging!

Related Tools