Back to Home
Published: June 2026•By Web Util Slyce Team•7 min read
JSON Schema — Write Schemas for Data Validation
Learn how to write JSON Schema to validate your JSON data. Generate schemas with our JSON Schema Generator.
Basic Schema
The simplest schema just declares the expected type.
JSON Schema
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer" },
"email": { "type": "string" }
},
"required": ["name", "email"]
}Valid JSON ✓
{
"name": "John",
"email": "john@example.com",
"age": 30
}Common Validation Keywords
| Keyword | Example | Description |
|---|---|---|
| type | "type": "string" | Must be: string, number, integer, boolean, null, object, array |
| required | "required": ["name"] | Array of required property names |
| minimum / maximum | "minimum": 0, "maximum": 100 | Numeric range constraints |
| minLength / maxLength | "minLength": 3, "maxLength": 50 | String length constraints |
| pattern | "pattern": "^[a-z]+$" | Regex pattern the string must match |
| enum | "enum": ["admin", "user"] | Value must be one of the listed options |
| format | "format": "email" | Semantic format (email, uri, date, uuid) |
| default | "default": "user" | Default value when property is absent |
| additionalProperties | "additionalProperties": false | Disallow properties not defined in the schema |
Advanced Schema Example
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"username": {
"type": "string",
"minLength": 3,
"maxLength": 20,
"pattern": "^[a-zA-Z][a-zA-Z0-9_]+$"
},
"email": {
"type": "string",
"format": "email"
},
"role": {
"type": "string",
"enum": ["admin", "user", "viewer"],
"default": "user"
},
"scores": {
"type": "array",
"items": { "type": "number", "minimum": 0, "maximum": 100 },
"minItems": 1
},
"metadata": {
"type": "object",
"additionalProperties": { "type": "string" }
}
},
"required": ["username", "email"]
}