A single misplaced comma or wrong quote type makes an entire JSON file invalid. Unlike HTML, which browsers render despite many errors, a parser reading JSON stops completely at the first error it encounters. Knowing the common mistakes makes debugging much faster.
The Most Common JSON Errors
1. Missing Comma Between Items
Wrong: ``json { "name": "Ali" "age": 30 } ``
Correct: ``json { "name": "Ali", "age": 30 } ``
Every item in an object or array must be separated by a comma, except the last one.
2. Trailing Comma After the Last Item
Wrong: ``json { "name": "Ali", "age": 30, } ``
Correct: ``json { "name": "Ali", "age": 30 } ``
The last item before a closing } or ] must not have a comma. This is the most common mistake for people coming from JavaScript or Python where trailing commas are allowed.
3. Single Quotes Instead of Double Quotes
Wrong: {'name': 'Ali'} Correct: {"name": "Ali"}
JSON requires double quotes for both keys and string values. Single quotes are not valid JSON.
4. Unquoted Keys
Wrong: {name: "Ali"} Correct: {"name": "Ali"}
In JSON, keys must always be strings in double quotes. JavaScript objects allow unquoted keys; JSON does not.
5. Undefined or Function Values
Wrong: {"value": undefined} or {"fn": function() {}} Correct: {"value": null} (use null instead of undefined; functions can't be represented in JSON)
6. Unescaped Special Characters in Strings
If a string contains a double quote or backslash, it must be escaped:
Wrong: {"path": "C:\Users\file"} Correct: {"path": "C:\\Users\\file"}
Special escapes in JSON strings:
\"for a double quote\\for a backslash\nfor a newline\tfor a tab
Fixing JSON Quickly
- Open JSON Formatter.
- Paste the JSON.
- The error message and position (line number) point to the problem.
- Fix the error and reformat.
For understanding JSON structure before fixing it, see what is JSON: a beginner's guide.
When to Use a Linter vs the Formatter
The JSON Formatter validates and pretty-prints JSON — ideal when you have raw or minified JSON that needs to be readable, or when you're not sure if it's valid. A JSON linter in a code editor (like VS Code's built-in JSON support) catches errors as you type — more useful when actively writing JSON configs or API payloads. Both check validity; the formatter is better for cleaning up external JSON you've received, while a linter integrates into the writing workflow.
Validating JSON Before Deployment
Before deploying configuration files (package.json, laravel config files exported to JSON, API response structures) it's worth running them through a validator. A single broken config file can crash an application or prevent deployment. The JSON Formatter validates in one click — paste, check, deploy. For teams, adding a JSON lint step to a CI/CD pipeline catches errors before they reach production.