How to Fix Invalid JSON
Quick Answer
Invalid JSON errors are usually caused by syntax mistakes like missing quotes, trailing commas, or mismatched brackets. Use a JSON validator to identify the exact error location, then fix the syntax issues manually or let the tool format it for you.
Common Causes of Invalid JSON
- Missing quotes - Property names and string values must be in double quotes, not single quotes
- Trailing commas - JSON doesn't allow commas after the last item in an array or object
- Unquoted property names - Unlike JavaScript, JSON requires quotes around all property names
- Mismatched brackets - Every
{needs a}and every[needs a] - Undefined values - JSON only supports strings, numbers, booleans, null, arrays, and objects
How to Fix Invalid JSON (3 Steps)
- Identify the error - Copy your JSON and paste it into the JSON Formatter. The tool will show you the exact line and character where the error occurs.
-
Fix the syntax - Based on the error message, correct the issue. Common
fixes include:
- Add missing quotes around property names
- Remove trailing commas
- Close unclosed brackets
- Validate the result - Paste your corrected JSON back into the validator to confirm it's now valid. The tool will also format it with proper indentation.
Example: Fixing a Common Error
Invalid JSON:
{
name: 'John', // Missing quotes, single quotes
age: 30, // Trailing comma below
}
Valid JSON:
{
"name": "John",
"age": 30
}
Frequently Asked Questions
What does "Unexpected token" mean in JSON?
This error means the JSON parser encountered a character it didn't
expect at that position. Usually it's a missing quote, an extra comma, or an unquoted
property name. The error message will tell you the line and column number.
Can I use single quotes in JSON?
No. JSON strictly requires double quotes for all strings and
property names. Single quotes are not valid JSON syntax, even though they work in
JavaScript.
Why does my JSON work in JavaScript but not in a validator?
JavaScript is more lenient than JSON. It allows single quotes,
unquoted property names, and trailing commas. JSON is a strict data format that doesn't
allow these shortcuts.
How do I find JSON errors in a large file?
Use an online JSON formatter that shows line numbers. Paste your
JSON
and the tool will highlight the exact location of the error, making it easy to find and
fix even in large files.