How to Fix Invalid JSON Errors Fast
Getting a "JSON parse error" or "unexpected token" message? These cryptic errors almost always come down to a few common mistakes that are easy to fix once you know where to look.
Quick Answer
Most invalid JSON errors come from trailing commas, missing quotes, or unmatched brackets. Paste your JSON into the free formatter at dotsapps.com to instantly find and fix the exact problem.
Common JSON Syntax Errors and What They Mean
JSON is strict about formatting. Even one wrong character breaks the whole thing. Here are the most common mistakes:
- Trailing commas — A comma after the last item in an array or object. JavaScript allows this, but JSON does not.
- Single quotes — JSON requires double quotes around keys and string values. Single quotes will cause a parse error.
- Unquoted keys — Every key in JSON must be wrapped in double quotes.
{name: "John"}is invalid.{"name": "John"}is correct. - Missing brackets — An unclosed
[or{somewhere in your data. - Comments — JSON does not support comments. Remove any
//or/* */lines.
These five issues cause over 90% of all JSON errors. A formatter that highlights the exact line and position saves you from scanning hundreds of lines by hand.
How to Validate JSON Online in Seconds
You don't need to install anything to check your JSON. An online validator gives you instant feedback with the exact error location.
Open the JSON Formatter tool on dotsapps.com. Paste your JSON into the input area. The tool checks it immediately. If there's an error, you'll see the line number and a description of what went wrong.
Once valid, the tool formats your JSON with proper indentation so you can actually read it. This is especially helpful when dealing with minified API responses that are one giant line of text.
Fixing JSON Errors from API Responses
APIs sometimes return malformed JSON. This can happen when the server crashes mid-response, when there's a character encoding issue, or when the API wraps JSON in extra characters.
A common problem is a BOM (byte order mark) at the start of the response. It's invisible but breaks parsers. Another issue is when APIs return JSONP (JSON wrapped in a function call) instead of plain JSON.
If your API response starts with something like callback(, strip that wrapper and the closing ) before parsing. If you see weird characters at the very start, try copying just the JSON portion — from the first { or [ to the last } or ].
Paste the cleaned-up response into the formatter to confirm it's valid before using it in your code.
JSON Error Messages in Different Languages
Different tools show different error messages for the same problem. Here's a quick translation guide:
- "Unexpected token" — Usually means a trailing comma, missing quote, or wrong character at that position.
- "Unterminated string" — A string value is missing its closing double quote.
- "Expected ',' or '}'" — You're missing a comma between items or a closing bracket.
- "JSON.parse: bad control character" — A special character like a tab or newline is inside a string without being escaped.
When you see these errors in your browser console or backend logs, copy the JSON and paste it into a validator. The validator pinpoints the exact position, so you don't have to guess.
Tips to Avoid JSON Errors in the Future
Prevention is easier than debugging. Follow these habits:
- Always use a JSON-aware editor. VS Code, Sublime Text, and others highlight JSON syntax errors as you type.
- Generate JSON with code, not by hand. Use
JSON.stringify()or your language's equivalent instead of building JSON strings manually. - Validate before sending. If your app sends JSON to an API, validate it before the request. This catches problems early.
- Keep a formatter bookmarked. When something breaks, you want to check it fast.
How to Do It: Step-by-Step
- 1
Open the JSON Formatter tool at dotsapps.com
- 2
Paste your JSON into the input area
- 3
Read the error message — it shows the line number and what's wrong
- 4
Fix the issue (add a missing quote, remove a trailing comma, etc.)
- 5
Click Format to see your clean, validated JSON
Frequently Asked Questions
What causes invalid JSON errors?
The most common causes are trailing commas, single quotes instead of double quotes, unquoted keys, missing brackets, and comments. JSON has strict syntax rules that don't allow any of these.
How do I find the error in a large JSON file?
Use an online JSON validator that shows line numbers. Paste your JSON and the tool will point to the exact line and character position where the error occurs.
Can I fix JSON errors automatically?
Some errors like formatting and indentation can be fixed automatically by a formatter. But structural errors like missing brackets or wrong data types need manual fixes based on what the data should be.
Why does my JSON work in JavaScript but not in other tools?
JavaScript is more lenient than the JSON spec. It allows trailing commas, single quotes, unquoted keys, and comments. Strict JSON parsers reject all of these.
Is there a difference between JSON validation and formatting?
Yes. Validation checks if your JSON follows the correct syntax rules. Formatting makes valid JSON easier to read by adding indentation and line breaks. A good tool does both at once.
Ready to Try It?
JSON Formatter is free, private, and works right in your browser. No sign-up needed.
Open JSON Formatter