JSON Schema is a structural contract for JSON: it describes required fields, field types, arrays, nested objects, and optional format rules.
It is useful for API debugging, config validation, low-code forms, and data imports because it catches shape problems before data reaches business logic.
Start With a JSON Sample
{
"id": 1001,
"email": "user@example.com",
"roles": ["admin"],
"active": true
}This object contains a number, a string, an array, and a boolean. A Schema can describe each field and decide which fields are required.
{
"type": "object",
"required": ["id", "email", "roles", "active"],
"properties": {
"id": { "type": "number" },
"email": { "type": "string", "format": "email" },
"roles": {
"type": "array",
"items": { "type": "string" }
},
"active": { "type": "boolean" }
}
}Common JSON Schema Keywords
| Keyword | Purpose | Example |
|---|---|---|
| type | Restricts the base value type | object, array, string, number |
| properties | Describes fields in an object | email, roles, active |
| required | Lists fields that must exist | id, email |
| items | Describes array item types | each role is a string |
| format | Adds semantic hints for strings | email, uri, date-time |
How to Use It for API Validation
- Generate a first Schema from a realistic API sample.
- Refine required, format, enum, minLength, and other constraints from the API contract.
- Validate real request or response JSON against the Schema.
- Use the error path to locate the exact field that needs attention.
Summary
JSON Schema turns a data shape into executable validation rules. That makes API and data pipeline errors easier to catch and explain.