Last updated
JSON Schema Validator Examples
The JSON Schema Validator checks JSON data against a schema definition, reporting exactly which constraints are violated. Below are examples of validation rules and their results.
Example: Required Properties
// Schema:
{
"type": "object",
"required": ["id", "name", "email"],
"properties": {
"id": { "type": "integer" },
"name": { "type": "string" },
"email": { "type": "string" }
}
}
// Valid data:
{ "id": 1, "name": "Alice", "email": "alice@example.com" }
→ ✓ Valid
// Invalid data (missing email):
{ "id": 1, "name": "Alice" }
→ ✗ Validation error:
Path: (root)
Error: Missing required property 'email'
Example: Type Validation
// Schema:
{
"type": "object",
"properties": {
"age": { "type": "integer" },
"score": { "type": "number" },
"active": { "type": "boolean" },
"tags": { "type": "array" }
}
}
// Invalid data:
{
"age": "thirty",
"score": "98.5",
"active": "yes",
"tags": "admin,user"
}
// Validation errors:
Path: /age — Expected integer, got string "thirty"
Path: /score — Expected number, got string "98.5"
Path: /active — Expected boolean, got string "yes"
Path: /tags — Expected array, got string "admin,user"
Example: String Constraints
// Schema:
{
"type": "object",
"properties": {
"username": {
"type": "string",
"minLength": 3,
"maxLength": 20,
"pattern": "^[a-zA-Z0-9_]+$"
},
"email": {
"type": "string",
"format": "email"
},
"website": {
"type": "string",
"format": "uri"
}
}
}
// Invalid data:
{
"username": "ab",
"email": "not-an-email",
"website": "not a url"
}
// Validation errors:
Path: /username — String length 2 is less than minimum 3
Path: /email — String does not match format "email"
Path: /website — String does not match format "uri"
// Also invalid:
{ "username": "user name with spaces" }
→ Path: /username — String does not match pattern "^[a-zA-Z0-9_]+$"
Example: Number Constraints
// Schema:
{
"type": "object",
"properties": {
"age": { "type": "integer", "minimum": 0, "maximum": 150 },
"price": { "type": "number", "minimum": 0, "exclusiveMinimum": true },
"quantity": { "type": "integer", "multipleOf": 5 },
"percentage": { "type": "number", "minimum": 0, "maximum": 100 }
}
}
// Invalid data:
{
"age": -5,
"price": 0,
"quantity": 7,
"percentage": 105
}
// Validation errors:
Path: /age — Value -5 is less than minimum 0
Path: /price — Value 0 must be greater than 0 (exclusive minimum)
Path: /quantity — Value 7 is not a multiple of 5
Path: /percentage — Value 105 is greater than maximum 100
Example: Array Validation
// Schema:
{
"type": "object",
"properties": {
"tags": {
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"maxItems": 5,
"uniqueItems": true
},
"scores": {
"type": "array",
"items": { "type": "number", "minimum": 0, "maximum": 100 }
}
}
}
// Invalid data:
{
"tags": [],
"scores": [85, 92, 105, -5]
}
// Validation errors:
Path: /tags — Array has 0 items, minimum is 1
Path: /scores/2 — Value 105 is greater than maximum 100
Path: /scores/3 — Value -5 is less than minimum 0
// Also invalid:
{ "tags": ["js", "js", "python"] }
→ Path: /tags — Array items must be unique (duplicate: "js")
Example: Enum Validation
// Schema:
{
"type": "object",
"properties": {
"status": {
"type": "string",
"enum": ["pending", "active", "completed", "cancelled"]
},
"priority": {
"type": "string",
"enum": ["low", "medium", "high"]
}
}
}
// Invalid data:
{
"status": "in-progress",
"priority": "urgent"
}
// Validation errors:
Path: /status — Value "in-progress" is not one of: pending, active, completed, cancelled
Path: /priority — Value "urgent" is not one of: low, medium, high
Example: allOf / anyOf / oneOf
// Schema using anyOf (must match at least one):
{
"anyOf": [
{ "type": "string", "format": "email" },
{ "type": "string", "format": "uri" }
]
}
// Valid: "alice@example.com" (matches email format)
// Valid: "https://example.com" (matches uri format)
// Invalid: "not-email-or-url"
→ Does not match any of the schemas in anyOf
// Schema using oneOf (must match exactly one):
{
"oneOf": [
{ "type": "integer" },
{ "type": "string" }
]
}
// Valid: 42 (matches integer only)
// Valid: "hello" (matches string only)
// Invalid: 3.14 (matches neither integer nor string exactly)
Batch Validation Results
Validating 5 records against User schema...
Record 1: { "id": 1, "name": "Alice", "email": "alice@example.com" }
→ ✓ Valid
Record 2: { "id": 2, "name": "Bob" }
→ ✗ Missing required: email
Record 3: { "id": "three", "name": "Carol", "email": "carol@example.com" }
→ ✗ /id: Expected integer, got string
Record 4: { "id": 4, "name": "", "email": "dave@example.com" }
→ ✗ /name: String length 0 is less than minimum 1
Record 5: { "id": 5, "name": "Eve", "email": "eve@example.com" }
→ ✓ Valid
Summary: 2 valid, 3 invalid
Paste your JSON Schema in the left panel and your JSON data in the right panel to validate it. Detailed error messages show exactly which constraints are violated and where.