JSON Schema describes the shape of JSON data and can validate documents automatically.
type limits the value type. properties defines child fields. required lists mandatory keys. items describes array elements.
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"required": ["name", "age"],
"properties": {
"name": {"type": "string"},
"age": {"type": "integer", "minimum": 0}
}
}
enum allows a fixed set of values. const requires exactly one value.
{"role": {"enum": ["admin", "editor", "viewer"]}}
$ref points to another schema definition so complex documents stay maintainable.
{"$defs":{"id":{"type":"integer"},"type":"object","properties":{"id":{"$ref":"#/$defs/id"}}}