JSON Schema is a vocabulary that lets you annotate and validate JSON documents. Think of it as a type system for JSON — you describe the shape of valid data, and validators check that documents conform to it.
Why Use JSON Schema?
- ·Validate API request/response payloads
- ·Document the expected shape of your data
- ·Generate forms, TypeScript types, and documentation automatically
- ·Catch data quality issues early in data pipelines
Basic Types
Every schema has a "type" keyword. JSON Schema supports: string, number, integer, boolean, null, object, and array.
{
"type": "object",
"properties": {
"name": { "type": "string" },
"age": { "type": "integer", "minimum": 0 },
"email": { "type": "string", "format": "email" },
"active": { "type": "boolean" }
},
"required": ["name", "email"]
}String Constraints
- ·minLength / maxLength — character count bounds
- ·pattern — validates against a regex: "pattern": "^[A-Z]{2}[0-9]{6}quot;
- ·format — semantic validation: "email", "date-time", "uri", "uuid"
- ·enum — restrict to specific values: "enum": ["draft", "published", "archived"]
Object Validation
{
"type": "object",
"properties": {
"status": { "enum": ["active", "inactive"] }
},
"required": ["status"],
"additionalProperties": false
}Setting "additionalProperties": false makes the schema strict — any field not listed in "properties" will fail validation. This is great for catching typos in field names.
Array Validation
{
"type": "array",
"items": { "type": "string" },
"minItems": 1,
"maxItems": 10,
"uniqueItems": true
}Combining Schemas
JSON Schema provides keywords to combine schemas logically.
- ·allOf — must be valid against ALL sub-schemas (like intersection)
- ·anyOf — must be valid against AT LEAST ONE sub-schema (like union)
- ·oneOf — must be valid against EXACTLY ONE sub-schema
- ·not — must NOT be valid against the sub-schema
Tip: Use our JSON Schema Validator and JSON Type Generator tools to validate documents and auto-generate schemas from sample JSON.