JSON Validation — Complete Guide
Free Online JSON Formatter & Validator
Validate JSON instantly with error highlighting and line numbers. Free and private.
Open JSON Formatter & Validator →What is JSON validation?
JSON validation checks that a JSON string conforms to the JSON specification (RFC 8259). A JSON validator tells you whether your JSON is syntactically correct and, if not, exactly where the error is.
There are two levels of JSON validation:
- Syntax validation — is the JSON structurally valid? (correct quotes, brackets, commas)
- Schema validation — does the JSON conform to a defined structure? (right fields, right types)
Most common JSON errors
| Error | Example (broken) | Fix |
|---|---|---|
| Unquoted key | {name: "Ada"} | {"name": "Ada"} |
| Single quotes | {'name': 'Ada'} | {"name": "Ada"} |
| Trailing comma | {"a": 1, "b": 2,} | {"a": 1, "b": 2} |
| Missing comma | {"a": 1 "b": 2} | {"a": 1, "b": 2} |
| Comments | {"a": 1 // comment} | Remove comments (JSON has none) |
| undefined value | {"a": undefined} | Use null instead |
| Unescaped quotes | {"a": "He said "hi""} | Escape as \" |
| NaN / Infinity | {"a": NaN} | Use null or a number string |
For a step-by-step repair walkthrough, see how to fix invalid JSON.
How to validate JSON online
- Open the JSON Formatter & Validator
- Paste your JSON into the input panel
- Click Format — any errors are highlighted with the line number and a description
- Fix the error and revalidate
Validate JSON in code
function isValidJSON(str) {
try {
JSON.parse(str);
return true;
} catch (e) {
return false;
}
}
// With error message
function validateJSON(str) {
try {
return { valid: true, data: JSON.parse(str) };
} catch (e) {
return { valid: false, error: e.message };
}
}For more JavaScript examples, see how to validate JSON in JavaScript.
import json
def validate_json(text):
try:
data = json.loads(text)
return {"valid": True, "data": data}
except json.JSONDecodeError as e:
return {"valid": False, "error": str(e), "line": e.lineno}JSON Schema validation
Syntax validation only tells you if the JSON is parseable. JSON Schema lets you define the exact structure you expect — required fields, data types, formats, and constraints — and validate any JSON document against that schema.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["id", "name", "email"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string", "minLength": 1 },
"email": { "type": "string", "format": "email" },
"age": { "type": "integer", "minimum": 0, "maximum": 150 }
},
"additionalProperties": false
}Frequently asked questions
// and /* */ comments. It's used in VS Code configuration files (settings.json, tsconfig.json). Standard JSON parsers reject JSONC — you need a JSONC-aware parser to handle it.Try it now — free & private
Runs entirely in your browser. No sign-up, no uploads, no tracking.
Open JSON Formatter & Validator →