JSON Schema Validator
Overview
JSON Schema Validator is a powerful tool for validating JSON data against predefined schemas. It ensures that your JSON data conforms to expected structures, data types, and constraints.
Features
Supported JSON Schema Keywords
- type: Validate data type (string, number, integer, boolean, array, object, null)
- properties: Define object property schemas
- required: Specify required object properties
- additionalProperties: Control whether extra properties are allowed
- items: Define array item schemas (single schema or tuple validation)
- minItems / maxItems: Set array length constraints
- uniqueItems: Require all array items to be unique
- enum: Restrict values to a specific set
- const: Require an exact constant value
- minimum / maximum: Set numeric range constraints
- exclusiveMinimum / exclusiveMaximum: Exclusive numeric bounds
- multipleOf: Require values to be multiples of a number
- minLength / maxLength: Set string length constraints
- pattern: Validate strings against regex patterns
- format: Validate built-in formats (email, uri, etc.)
- allOf: Data must match all sub-schemas
- anyOf: Data must match at least one sub-schema
- oneOf: Data must match exactly one sub-schema
- $ref: Reference another schema (basic support)
Example Usage
Basic Object Validation
JSON Data:
{
"name": "John Doe",
"age": 30,
"email": "[email protected]"
}
JSON Schema:
{
"type": "object",
"properties": {
"name": { "type": "string", "minLength": 1 },
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"email": { "type": "string", "format": "email" }
},
"required": ["name", "age"]
}
Array Validation
JSON Data:
{
"tags": ["javascript", "typescript", "vue"]
}
JSON Schema:
{
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"uniqueItems": true
}
}
}
Nested Object Validation
JSON Data:
{
"user": {
"id": 123,
"profile": {
"firstName": "Jane",
"lastName": "Smith"
}
}
}
JSON Schema:
{
"type": "object",
"properties": {
"user": {
"type": "object",
"properties": {
"id": { "type": "integer" },
"profile": {
"type": "object",
"properties": {
"firstName": { "type": "string" },
"lastName": { "type": "string" }
},
"required": ["firstName", "lastName"]
}
},
"required": ["id", "profile"]
}
}
}
Common Validation Errors
| Error |
Cause |
Solution |
| Missing required field |
Required property not found |
Add the missing property |
| Expected type X, got Y |
Data type mismatch |
Correct the data type |
| Additional property not allowed |
Extra property when additionalProperties: false |
Remove extra property or allow it |
| String does not match pattern |
Regex pattern validation failed |
Update string to match pattern |
| Array must have at least X items |
Array too short |
Add more items or adjust minItems |
| Value must be one of |
enum constraint failed |
Use one of the allowed values |
Supported JSON Schema Versions
- draft-04
- draft-06
- draft-07
- 2019-09
- 2020-12
Tips for Writing Effective Schemas
- Use descriptive property names - Makes validation errors clearer
- Set appropriate constraints - Balance flexibility with strictness
- Document your schemas - Use
description and title fields
- Test edge cases - Validate with boundary values
- Use
additionalProperties: false - Catch typos in property names
- Leverage
required sparingly - Only enforce truly mandatory fields