JSON Schema Definition
JSON Schema is a declarative specification language for describing the structure and validation constraints of JSON documents. A JSON Schema is itself a valid JSON document that uses reserved keywords like type, properties, required, and format.
Key JSON Schema Keywords (Draft-07)
type— Value type: string, number, integer, boolean, array, object, null.properties— Defines the expected keys and their schemas for an object.required— Array of property names that must be present.format— Semantic format: "date-time", "email", "uuid", "uri".enum— Restricts the value to a specific set of allowed values.minimum/maximum— Numeric range constraints.minLength/maxLength— String length constraints.pattern— Regular expression constraint for strings.items— Schema for array elements.$ref— Reference to another schema definition.
Common Validators Supporting JSON Schema
Ajv (JavaScript), jsonschema (Python), Jackson (Java), Newtonsoft (C#), OpenAPI/Swagger (all languages).
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"title": "User",
"required": ["id", "email", "name"],
"properties": {
"id": {
"type": "integer",
"minimum": 1
},
"email": {
"type": "string",
"format": "email"
},
"name": {
"type": "string",
"minLength": 2,
"maxLength": 100
},
"role": {
"type": "string",
"enum": ["admin", "editor", "viewer"]
},
"createdAt": {
"type": "string",
"format": "date-time"
}
}
}