I've probably made every single JSON error on this list at least twice. The first time, I spent an hour staring at the screen. The second time, I knew exactly what to look for. Let me save you that first hour.
Here's my collection of the most common JSON errors, complete with the exact error messages you'll see and the quickest fix for each.
1. Missing Comma Between Items
The error that has caught me more times than I'd like to admit:
{
"name": "Alice"
"age": 30
}
Error: SyntaxError: Expected ',' or '}' after property value in JSON at position 22
The parser finds "age" right after the value "Alice" and doesn't know what to do with it. It's expecting either a comma (indicating another key-value pair) or a closing brace.
Fix: Add the missing comma:
{
"name": "Alice",
"age": 30
}
How to spot it fast: If your error message mentions Expected ',' somewhere, you're missing a separator. Look at the character just before the error position — it's probably the end of a string or number that should be followed by a comma.
2. Trailing Comma After Last Item
The opposite mistake — and equally common:
{
"name": "Alice",
"age": 30,
}
Error: SyntaxError: Unexpected token } in JSON at position 30
JavaScript allows trailing commas in object literals since ES2017. JSON does not. That comma after 30 tells the parser "there's another value coming" — but the next thing is }, and that's unexpected.
Fix: Remove the trailing comma:
{
"name": "Alice",
"age": 30
}
Pro tip: If you're generating JSON programmatically, use JSON.stringify() instead of building strings with template literals. It never produces trailing commas:
// Bad — manual string building
const bad = `{"name": "${name}", "age": ${age},}`; // trailing comma
// Good — JSON.stringify
const good = JSON.stringify({ name: name, age: age }); // always valid
3. Unquoted Keys
JSON requires double quotes around all keys. This is probably the most common mistake when someone writes JSON in a text editor without a validator open:
{
name: "Alice",
age: 30
}
Error: SyntaxError: Unexpected token n in JSON at position 2
The parser hits name and expects a quote character, a closing brace, or a special token. An unquoted identifier is none of those.
Fix: Wrap keys in double quotes:
{
"name": "Alice",
"age": 30
}
If you have a large file with unquoted keys, a batch search-and-replace won't work cleanly (you might replace values). Instead, use a tool that validates and auto-fixes. The JSON Formatter highlights unquoted keys and shows you the exact line so you can fix them one by one.
4. Wrong Bracket Type
Mixing up brackets is another classic:
{
"users": [
{"id": 1, "name": "Alice"}
)
}
Error: SyntaxError: Unexpected token ) in JSON at position 45
A ) where ] should be. The parser was tracking an array context (opened with [), so it expects ] to close it.
Fix: Match your bracket types:
{
"users": [
{"id": 1, "name": "Alice"}
]
}
Quick check: When you see Unexpected token ) or Unexpected token }, look at the unmatched bracket in the error message, then trace back to find its opening counterpart.
5. Using Single Quotes Instead of Double Quotes
JSON is strict about quotes — double quotes only:
{"name": 'Alice', 'age': 30}
Error: SyntaxError: Unexpected token ' in JSON at position 10
Fix: Replace all single quotes with double quotes, and escape any internal double quotes:
{"name": "Alice", "age": 30}
When this gets tricky: String values that contain apostrophes. If you have {"description": "It's a test"}, that's perfectly valid JSON because the apostrophe is a single quote inside double-quoted content. The serializer handles it correctly.
6. Null and Undefined Confusion
JavaScript serializers and JSON parsers handle null differently from undefined:
const obj = {
name: "Alice",
deletedField: undefined,
emptyField: null
};
console.log(JSON.stringify(obj));
// {"name":"Alice","emptyField":null}
// Note: deletedField is completely missing!
Behavior: JSON.stringify() silently drops keys with undefined values. It keeps keys with null values. This mismatch can cause subtle bugs — you think a field exists in the JSON, but it silently disappeared.
Fix: If you need undefined to be present in JSON, convert it to null explicitly:
function serialize(v) {
return v === undefined ? null : v;
}
const obj = {
name: "Alice",
deletedField: serialize(undefined), // becomes null
};
console.log(JSON.stringify(obj));
// {"name":"Alice","deletedField":null}
7. Missing Quote Around String Value
When a string value has no quotes:
{"name": Alice}
Error: SyntaxError: Unexpected token A in JSON at position 10
Fix: Quote string values:
{"name": "Alice"}
This one is easy to miss when you're adding a new field quickly. If Alice is not a number, boolean, null, array, or object, it needs quotes.
8. Number with Leading Zeros
{"zip": 02134}
Error (some parsers): SyntaxError: Unexpected number in JSON at position 8
JSON numbers don't allow leading zeros (except 0 itself). Different parsers handle this differently — some silently round it, some throw.
Fix: Use a string for zip codes or remove leading zeros:
{"zip": "02134"}
How to Batch-Fix Common Errors
When you're dealing with a large, broken JSON file, fixing each error individually is painful. Here's my workflow:
- Validate first — find all errors before fixing any
- Classify errors — are they all trailing commas? All unquoted keys?
- Fix systematically — address the most common error type first (it often cascades)
The JSON Formatter validates your JSON and reports every error with line numbers. Fix them in order from top to bottom — earlier fixes often resolve downstream errors.
FAQ
Q: Can I use JavaScript's try/catch to handle JSON parse errors gracefully?
A: Yes. Always wrap JSON.parse() in a try/catch, especially when parsing user-generated or API data. Log the raw input for debugging.
Q: Why does my JSON work in Chrome DevTools but not in Node.js?
A: Chrome DevTools has a relaxed JSON parser that allows trailing commas and single quotes. Node's native JSON.parse() is strict.
Q: What's the fastest way to check if a file is valid JSON?
A: node -e "console.log(JSON.parse(require('fs').readFileSync('file.json','utf8')))" — or paste it into an online validator.
Q: How do I handle JSON with comments?
A: JSON doesn't support comments. Remove them before parsing. Some config formats like JSON5 or HJSON allow comments — consider those if you need them.
Q: Is there a way to auto-fix trailing commas?
A: Yes. A search-and-replace on ,}\n to }\n catches most cases, but be careful not to break strings that contain ,}. A dedicated formatter is safer.
Q: What does "Unexpected number" mean in a JSON error?
A: It usually means a number has invalid syntax — leading zeros, two decimal points, or a number in a context where a key or string was expected.
Q: Can I use undefined in JSON?
A: No. JSON has null but not undefined. If a field's value is undefined, JSON.stringify silently removes it.
Q: How do I fix a JSON file that's too large to edit by hand?
A: Upload it to a tool that handles large files. The JSON Formatter supports file upload (.json, .txt, .log) and validates/renders the full content without crashing.
Bookmark this list, or better yet, just use the JSON Formatter and let it catch these errors before you spend time debugging.