Back to Blog
Developer Tools

How to Debug JSON Syntax Errors โ€” Find the Exact Line With a JSON Formatter

2026-06-03 4 min read

JSON syntax errors are cryptic. A good formatter pinpoints the exact location of missing commas, trailing commas, and unescaped quotes.

JSON syntax errors can be infuriating. The error message says "unexpected token at position 1847" and you're staring at 2000 characters of minified text trying to find a single missing comma. There are faster ways to locate the problem.

The most common JSON syntax errors

After debugging hundreds of these, the usual suspects are always the same:

  • Trailing comma: {"key": "value",} โ€” the comma after the last item is illegal in JSON
  • Single quotes: {"key": 'value'} โ€” JSON requires double quotes everywhere
  • Unquoted keys: {key: 'value'} โ€” valid JavaScript but not valid JSON
  • Unescaped quotes: A string containing a " character must escape it as \"
  • Undefined or NaN: These JavaScript values don't exist in JSON

Finding errors quickly

Step one: format the JSON first. Paste it into a formatter and it will immediately tell you the line and column of the error. Working with formatted JSON makes the problem visible where minified text doesn't.

Step two: use a JSON parser that gives good error messages. Python's is excellent:

python3 -c "import json; json.loads(open('data.json').read())"
# Gives: json.JSONDecodeError: Expecting ',' delimiter: line 14 column 3 (char 287)

Node.js also gives line/column info in newer versions. The browser console JSON parser is less helpful but still gives you the character position.

Debugging escaped strings

One of the trickier cases is JSON that's been double-escaped. This happens when JSON is stored as a string inside another JSON string. You see things like:

{
  "payload": "{"user":{"id":1,"name":"Alice"}}"
}

The inner string looks like JSON but it's a string value. You need to parse the outer JSON first, then parse the payload field separately. This pattern often comes from APIs that serialize their response body before embedding it.

A systematic debugging approach

If the formatter can't find it, try binary search. Take the first half of the JSON and paste it into a parser (add a closing brace to make it parseable). If it passes, the error is in the second half. Keep halving until you isolate the problem. It sounds tedious but it's actually faster than eyeballing 5000 characters.

Use our JSON Formatter to paste and diagnose any JSON. It highlights the error line directly in the editor.

json syntax error debug formatter

More Articles