Skip to content
toolbelt
Back to Guides

Fixing the JSON Error You Cannot Find

By ·

Updated

The parser says line 412 and you swear line 412 looks fine. Here is what actually goes wrong, and how to find it faster.

What is this tool?

Validating JSON means asking one question: does the browser parser accept this text? It says nothing about whether the data makes sense for your application. Those are different jobs, and confusing them wastes time.

How it works

I parse the text with the native JSON parser and catch the exception. The parser reports a character offset, which I convert to a line and column. That conversion matters: most tools report a position, and counting characters by hand is how you lose an afternoon.

Example

This fails:
{
  "name": "Ada",
  "tags": ["x", "y",],
}

Error: line 3, column 31 — trailing comma.

Delete both trailing commas and it parses.

When to use it

Before you send a payload and after you receive a weird one. Also when a config file fails to load at startup, which is when you least want to be debugging by eye.

Optimization Tips

The three things that cause most failures: a trailing comma, a single quote where a double quote belongs, and a comment. None of those are legal in JSON, even though all three work in JavaScript. If you need comments in config, you want JSON5 or YAML, not JSON.

Frequently Asked Questions

Does this check my data types?
No. It checks syntax only. A string where you expected a number passes validation and still breaks your app.
Can it fix the error for me?
No, and I would not trust a tool that tried. It tells you where the parser stopped and you decide what you meant.
Why does it report a different line than my editor?
Check your line endings. Windows CRLF and Unix LF can shift what the parser counts.
What if the file is huge?
It will still validate, but the error position is more useful than trying to scroll a 50 MB file looking for a comma.

Ready to try it out?

Put this knowledge into practice with our free tool.

Go to Tool

Related tools