TL;DR: JSON is picky — one wrong comma or quote will break everything. The most common culprits are trailing commas, single quotes, and missing brackets. A good validator pinpoints exactly where the problem is so you can fix it in seconds.
The Heartbreak of Broken JSON
Let me paint you a picture. You've been working on a feature all afternoon. Everything looks perfect. You hit deploy and... the whole app crashes. The culprit? A single missing comma in a JSON config file. One tiny character, and your Friday evening plans just got cancelled.
JSON has zero tolerance for mistakes. Unlike JavaScript (which is pretty forgiving), JSON follows a strict specification that doesn't bend. A missing comma? Error. A single quote? Error. A trailing comma that JavaScript would happily ignore? You guessed it — error.
What JSON Parse Errors Actually Look Like
When you feed bad JSON to JSON.parse(), JavaScript throws a SyntaxError. Here's what happens in practice:
try {
JSON.parse('{"name": "Alice", "age": 30,}');
} catch (e) {
console.log(e.message);
// "Expected double-quoted property name in JSON at position 28"
}
The error message tells you the character position where things went sideways. Position 28 is the closing brace } — the parser was expecting another key-value pair after that trailing comma but found the end of the object instead.
Here's the frustrating part: different browsers give you different error messages for the exact same problem:
- Chrome/Node.js: "Expected double-quoted property name in JSON at position 28"
- Firefox: "JSON.parse: expected property name or '}' at line 1 column 29"
- Python: "Expecting property name enclosed in double quotes: line 1 column 29"
Dev Joke: A QA engineer walks into a bar. Orders 1 beer. Orders 0 beers. Orders 99999999 beers. Orders -1 beers. Orders a lizard. Orders NULL. First real customer walks in, asks where the bathroom is, and the bar bursts into flames.
The 7 JSON Mistakes You'll Make (We All Do)
1. Trailing Commas
This is the king of JSON errors, especially if you're coming from JavaScript where trailing commas are totally fine.
// BROKEN — that sneaky comma after "blue"
{
"colors": ["red", "green", "blue",]
}
// FIXED — remove it
{
"colors": ["red", "green", "blue"]
}
2. Missing Commas Between Properties
You copy-paste a new property and forget the comma. Classic move.
// BROKEN — where's the comma?
{
"name": "Alice"
"age": 30
}
// FIXED
{
"name": "Alice",
"age": 30
}
3. Single Quotes
JSON demands double quotes. Always. If you're a Python developer, this one will haunt you because Python's str() uses single quotes for dictionaries.
// BROKEN
{'name': 'Alice'}
// FIXED
{"name": "Alice"}
Python Tip: Always use json.dumps() to convert dictionaries to JSON strings, never str(). The str() function gives you Python syntax with single quotes, not valid JSON.
4. Unquoted Keys
JavaScript objects let you skip quotes on keys. JSON does not.
// BROKEN
{name: "Alice"}
// FIXED
{"name": "Alice"}
5. Unmatched Brackets
The deeper your nesting goes, the easier it is to lose track of a bracket.
// BROKEN — missing closing ] for the array
{
"users": [
{"name": "Alice"},
{"name": "Bob"}
}
// FIXED
{
"users": [
{"name": "Alice"},
{"name": "Bob"}
]
}
6. Comments
You might instinctively drop a comment in your JSON file. Unfortunately, standard JSON says nope.
// BROKEN
{
// This is a user's name
"name": "Alice"
}
// FIXED — just remove the comment
{
"name": "Alice"
}
7. Invalid Values
JSON supports six value types: string, number, boolean, null, object, and array. That's the full list. JavaScript extras like undefined, NaN, and Infinity are not invited to the party.
// BROKEN
{"value": undefined, "result": NaN, "limit": Infinity}
// FIXED
{"value": null, "result": null, "limit": 9999999}
A Smart Debugging Strategy
Got a huge JSON file with an error somewhere in the middle? Don't scroll aimlessly. Try this approach:
- Check the error position — Most parsers tell you the character offset or line number. Go there first.
- Look one line up — The real problem is often on the previous line (like a missing comma). The parser only notices when it hits the next token.
- Use binary search — For giant JSON files, delete the bottom half and see if the top half parses. Keep narrowing down.
- Don't build JSON by hand — If you're constructing JSON through string concatenation, stop. Use your language's JSON library.
A Handy Validation Function
Here's a little utility you can drop into any project:
function validateJSON(str) {
try {
const parsed = JSON.parse(str);
return { valid: true, data: parsed, error: null };
} catch (e) {
const posMatch = e.message.match(/position\s+(\d+)/);
const position = posMatch ? parseInt(posMatch[1]) : null;
let line = 1, column = 1;
if (position !== null) {
for (let i = 0; i < position && i < str.length; i++) {
if (str[i] === '\n') { line++; column = 1; }
else { column++; }
}
}
return {
valid: false,
data: null,
error: { message: e.message, position, line, column }
};
}
}
Prevention beats debugging: Never build JSON by string concatenation. Always use JSON.stringify(), json.dumps(), or your language's equivalent. Configure your editor with a JSON linter so errors get caught the moment you type them.
Beyond Syntax: JSON Schema Validation
Syntax validation tells you if your JSON is well-formed, but it doesn't tell you if the data makes sense. That's where JSON Schema comes in — it lets you define what your JSON should look like:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "email"],
"properties": {
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0 }
}
}
Think of it like a blueprint: syntax validation checks if you built a house, JSON Schema checks if you built the right house. Libraries like ajv (JavaScript) and jsonschema (Python) handle this at runtime.
Try It Yourself
Paste your JSON into our free validator to instantly find syntax errors with clear, human-readable explanations and exact line numbers.
Open JSON Formatter →