JSON is strict. A single misplaced comma or missing quote makes the entire file invalid. Validation checks that your JSON follows the rules.
| Error | What it means | Fix |
|---|---|---|
Unexpected token | A character was found where it wasn't expected | Check for stray commas, extra brackets, or unquoted strings |
Expected ',' or '}' | A comma or closing brace is missing | Add the missing comma or brace |
Expected '"' | A string is missing its opening or closing quote | Add double quotes around the key or string value |
Unexpected number | A number appeared where it isn't valid | Check for leading zeros or misplaced periods |
Trailing comma | A comma after the last element in an object/array | Remove the comma after the last item |
Option 1 — Online validators: Paste your JSON into websites like jsonlint.com or jsonformatter.org. They highlight errors instantly.
Option 2 — Code editors: VS Code, Sublime Text, and others highlight JSON errors automatically. Look for red squiggly lines.
Option 3 — Command line: Use tools like jq or language-specific parsers:
# Using jq (Linux/macOS)
jq . file.json
# Using Python
python -m json.tool file.json
# Using Node.js
node -e "JSON.parse(require('fs').readFileSync('file.json','utf8'))"
Invalid:
{
"name": "Alice",
age: 30, // key not in double quotes
"hobbies": ["art"] // valid
}
Valid:
{
"name": "Alice",
"age": 30, // added double quotes
"hobbies": ["art"]
}
Minified JSON is hard to read. Use pretty-printing to format it with indentation:
// Python
print(json.dumps(data, indent=2))
// JavaScript
JSON.stringify(data, null, 2)