JSON Schema is a declarative language for validating the structure, constraint requirements, and data types of JSON documents. It acts as a contract between API producers and consumers.
A Simple JSON Schema Example
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"type": "object",
"properties": {
"id": { "type": "integer" },
"username": { "type": "string", "minLength": 3 },
"email": { "type": "string", "format": "email" },
"role": { "type": "string", "enum": ["admin", "editor", "user"] }
},
"required": ["id", "username", "email"]
}