JSON Schema Validator Guide — Validate JSON Data Like a Pro
Published: July 22, 2026
JSON Schema is a powerful tool for defining the structure and constraints of JSON data. Whether you're validating API requests, ensuring database consistency, or generating documentation, JSON Schema helps you catch data quality issues before they cause problems.
What is JSON Schema?
JSON Schema is a vocabulary that allows you to annotate and validate JSON documents. It defines the expected structure, data types, and constraints for JSON data. Think of it as a contract that your JSON data must follow.
Basic Example
Here's a simple JSON Schema for a user object:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": ["name", "email"],
"properties": {
"name": {
"type": "string",
"minLength": 2,
"maxLength": 100
},
"email": {
"type": "string",
"format": "email"
},
"age": {
"type": "integer",
"minimum": 0,
"maximum": 150
},
"isActive": {
"type": "boolean"
}
}
}This schema validates that the JSON data:
- Is an object (not an array, string, or number)
- Has required fields
nameandemail - Has a
namethat's a string between 2-100 characters - Has a valid
emailformat - Has an optional
agethat's an integer between 0-150 - Has an optional
isActivethat's a boolean
Valid JSON data would be:
{
"name": "Alice Smith",
"email": "alice@example.com",
"age": 28,
"isActive": true
}Common Schema Keywords
| Keyword | Description | Example |
|---|---|---|
| type | Data type constraint | "string", "number", "object" |
| required | List of required properties | ["name", "email"] |
| minimum / maximum | Numeric range | {"minimum": 0, "maximum": 150} |
| minLength / maxLength | String length range | {"minLength": 2, "maxLength": 100} |
| pattern | Regex pattern for strings | "^[a-zA-Z]+$" |
| enum | List of allowed values | ["active", "inactive"] |
| format | Semantic format validation | "email", "date", "uri" |
| additionalProperties | Allow extra properties | false (disallow extras) |
Validating Arrays
You can also validate arrays and their items:
{
"type": "array",
"minItems": 1,
"maxItems": 10,
"uniqueItems": true,
"items": {
"type": "string",
"pattern": "^[a-z]+$"
}
}This validates an array of 1-10 unique lowercase strings.
Using OneOf / AnyOf / AllOf
JSON Schema supports conditional validation for complex scenarios:
{
"oneOf": [
{ "type": "string" },
{ "type": "number" }
]
}This allows either a string or a number, but not both and not any other type.
Real-World Use Cases
- API Request Validation — Ensure incoming API requests match expected formats before processing
- Contract Testing — Define API contracts with JSON Schema and validate responses automatically
- Configuration Files — Validate JSON config files against a schema to catch typos and missing fields
- Data Migration — Verify that migrated data conforms to the new schema
- Documentation Generation — JSON Schema can generate API documentation automatically
Auto-Generating Schema from JSON
Don't want to write schemas by hand? Use our JSON Schema Generator. Just paste your JSON data and it will automatically create the corresponding schema.
- JSON Schema Validator — validate data against a schema
- JSON Schema Generator — create schemas from data
- JSON Validator — basic JSON syntax validation