Type Keywords
| Keyword | Applies To | Description | Example |
|---|
type | Any | Restricts the value to a specific type | "type": "string" |
enum | Any | Value must be one of the listed values | "enum": ["draft", "published"] |
const | Any | Value must equal this exact value | "const": "active" |
default | Any | Default value (not enforced, informational) | "default": 0 |
title | Any | Short label for documentation | "title": "User Name" |
description | Any | Longer description for documentation | "description": "The user's full name" |
examples | Any | Example values for documentation | "examples": ["Alice", "Bob"] |
Valid type values: string, number, integer, boolean, object, array, null.
String Validations
| Keyword | Type | Example Value | Description |
|---|
minLength | integer | 1 | Minimum string length (inclusive) |
maxLength | integer | 255 | Maximum string length (inclusive) |
pattern | regex | "^[A-Z]{2}\\d{4}$" | Must match this regular expression |
format | string | "email" | Semantic format hint (see format table below) |
enum | array | ["low", "medium", "high"] | Value must be one of these strings |
contentMediaType | string | "application/json" | MIME type of encoded string content |
contentEncoding | string | "base64" | Encoding of the string (e.g., base64) |
Number Validations
| Keyword | Type | Example Value | Description |
|---|
minimum | number | 0 | Value must be >= this (inclusive) |
maximum | number | 100 | Value must be <= this (inclusive) |
exclusiveMinimum | number | 0 | Value must be > this (exclusive) |
exclusiveMaximum | number | 100 | Value must be < this (exclusive) |
multipleOf | number | 5 | Value must be divisible by this |
Use "type": "integer" to restrict to whole numbers. "type": "number" allows decimals.
Object Validations
| Keyword | Type | Description | Example |
|---|
properties | object | Defines schemas for known properties | "properties": {"name": {"type": "string"}} |
required | array | List of properties that must be present | "required": ["name", "email"] |
additionalProperties | boolean / schema | Controls extra properties beyond those in properties | "additionalProperties": false |
minProperties | integer | Minimum number of properties | "minProperties": 1 |
maxProperties | integer | Maximum number of properties | "maxProperties": 10 |
patternProperties | object | Schema for properties matching a regex pattern | "patternProperties": {"^x-": {"type": "string"}} |
propertyNames | schema | Schema that all property names must match | "propertyNames": {"pattern": "^[a-z]"} |
dependentRequired | object | If property A exists, property B is required | "dependentRequired": {"card": ["cvv"]} |
Array Validations
| Keyword | Type | Description | Example |
|---|
items | schema | Schema that all array items must match | "items": {"type": "string"} |
prefixItems | array of schemas | Schema for each positional item (tuple validation) | "prefixItems": [{"type": "string"}, {"type": "number"}] |
minItems | integer | Minimum number of items | "minItems": 1 |
maxItems | integer | Maximum number of items | "maxItems": 50 |
uniqueItems | boolean | All items must be unique | "uniqueItems": true |
contains | schema | At least one item must match this schema | "contains": {"type": "number"} |
minContains | integer | Minimum items matching contains | "minContains": 2 |
maxContains | integer | Maximum items matching contains | "maxContains": 5 |
Combining Schemas
| Keyword | Logic | Description | Example |
|---|
allOf | AND | Must match all of the listed schemas | "allOf": [{"type": "string"}, {"minLength": 1}] |
anyOf | OR | Must match at least one of the listed schemas | "anyOf": [{"type": "string"}, {"type": "number"}] |
oneOf | XOR | Must match exactly one of the listed schemas | "oneOf": [{"minimum": 0}, {"maximum": -1}] |
not | NOT | Must not match the given schema | "not": {"type": "null"} |
if / then / else | Conditional | Apply different schemas based on a condition | "if": {"properties": {"type": {"const": "business"}}}, "then": {"required": ["taxId"]} |
Format Values
Common values for the format keyword. Validation depends on the implementation — some treat these as annotations only.
| Format | Description | Example Value |
|---|
date-time | ISO 8601 date-time | "2025-03-10T14:30:00Z" |
date | ISO 8601 date | "2025-03-10" |
time | ISO 8601 time | "14:30:00Z" |
duration | ISO 8601 duration | "P3Y6M4DT12H30M5S" |
email | Email address (RFC 5321) | "user@example.com" |
idn-email | Internationalized email | "user@例え.jp" |
uri | Full URI (RFC 3986) | "https://example.com/path" |
uri-reference | URI or relative reference | "/path/to/resource" |
uuid | UUID (RFC 4122) | "550e8400-e29b-41d4-a716-446655440000" |
ipv4 | IPv4 address | "192.168.1.1" |
ipv6 | IPv6 address | "::1" |
hostname | Internet hostname (RFC 1123) | "api.example.com" |
regex | ECMA-262 regular expression | "^[a-z]+$" |
json-pointer | JSON Pointer (RFC 6901) | "/foo/bar/0" |
$ref — Reusing Schemas
Use $ref to reference shared definitions and avoid repetition:
{
"$defs": {
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"zip": { "type": "string", "pattern": "^\\d{5}$" }
},
"required": ["street", "city", "zip"]
}
},
"type": "object",
"properties": {
"billing": { "$ref": "#/$defs/address" },
"shipping": { "$ref": "#/$defs/address" }
}
}
| $ref Pattern | Points To |
|---|
#/$defs/name | Local definition in the same schema |
other.json | Root of an external schema file |
other.json#/$defs/name | Definition inside an external file |
https://example.com/schema.json | Remote schema by URL |
Complete Example Schema
A full schema for a user registration API request:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "https://api.example.com/schemas/user",
"title": "User Registration",
"description": "Schema for creating a new user account",
"type": "object",
"properties": {
"username": {
"type": "string",
"minLength": 3,
"maxLength": 30,
"pattern": "^[a-zA-Z0-9_]+$"
},
"email": {
"type": "string",
"format": "email"
},
"password": {
"type": "string",
"minLength": 8,
"maxLength": 128
},
"age": {
"type": "integer",
"minimum": 13,
"maximum": 150
},
"role": {
"type": "string",
"enum": ["user", "admin", "moderator"],
"default": "user"
},
"tags": {
"type": "array",
"items": { "type": "string", "maxLength": 50 },
"maxItems": 10,
"uniqueItems": true
},
"address": { "$ref": "#/$defs/address" }
},
"required": ["username", "email", "password"],
"additionalProperties": false,
"$defs": {
"address": {
"type": "object",
"properties": {
"street": { "type": "string" },
"city": { "type": "string" },
"country": { "type": "string", "minLength": 2, "maxLength": 2 },
"zip": { "type": "string" }
},
"required": ["street", "city", "country"]
}
}
}
Generate schemas automatically: Paste any JSON payload into our JSON Schema Generator to instantly create a valid JSON Schema — then customize from there.