What are JSON Schema Keywords?

JSON Schema keywords are predefined terms used to describe, structure, and validate JSON data. These keywords act as rules, which define how the data should be validated, interpreted, and documented, ensuring it follows the intended format.

Types of JSON Schema Keywords

There are seven main types of JSON Schema keywords:

  • Core Keywords: Define schema identity, references, and basic structure.
  • Applicator Keywords: Apply rules to specific parts of the data like properties or array items.
  • Validation Keywords: Set conditions and constraints for acceptable data.
  • Metadata Keywords: Add descriptive information like title, description, and examples.
  • Format & Content Keywords: Specify data formats (e.g., email, date) and media types.
  • Unevaluated Keywords: Handle data not covered by other keywords.
  • Annotation Keywords: Provide extra information without affecting validation.

Schema Keywords Example

Copy
{
	"$schema": "https://json-schema.org/draft/2020-12/schema",
	"title": "User",
	"type": "object",
	"properties": {
		"name": { "type": "string" },
		"age": { "type": "integer", "minimum": 0 },
		"email": { "type": "string", "format": "email" }
	},
	"required": ["name", "email"]
}

Alphabetical Reference

This table lists a total of 60 JSON Schema keywords, arranged in alphabetical order.

Keyword Description
$anchor Marks a local anchor for internal $ref usage
$comment Developer notes ignored by validators
$defs Holds reusable subschemas for reference
$dynamicAnchor Marks a dynamic anchor for context-aware refs
$dynamicRef Resolves a reference dynamically at runtime context
$id Defines a unique identifier for the schema
$recursiveAnchor Designates a recursion anchor for nested recursive refs
$recursiveRef Resolves a recursive reference back to an anchor
$ref References another schema by pointer or URI
$schema Declares the JSON Schema version in use
$vocabulary Lists vocabularies required by the schema
additionalProperties Schema for object properties not listed in properties
allOf Instance must validate against every listed schema
anyOf Instance must match at least one schema
contains Requires at least one array item to match a schema
contentEncoding Encoding of a string, for example base64
contentMediaType MIME type of the encoded string content
contentSchema Schema to validate decoded or embedded content
const Value must exactly match the given constant
dependentRequired Specifies additional required fields when a property exists
dependentSchemas Schemas applied when specified properties exist
dependencies Legacy keyword to require or apply schemas when props exist
else Schema applied when the if condition is false
enum Value must equal one of the listed options
exclusiveMaximum Number must be strictly less than this value
exclusiveMinimum Number must be strictly greater than this value
format Semantic format hint for string values
if Condition schema that triggers then/else
items Schema for items in an array
minContains Minimum matching items for contains
minimum Number must be greater than or equal to this value
minItems Minimum number of items in an array
minLength Minimum string length
minProperties Minimum number of object properties required
maxContains Maximum matching items for contains
maximum Number must be less than or equal to this value
maxItems Maximum number of items in an array
maxLength Maximum string length
maxProperties Maximum number of object properties allowed
multipleOf Number must be divisible by this value
not Instance must not match the given schema
oneOf Instance must match exactly one schema
pattern String must match the regular expression
patternProperties Schemas for property names matching a regex
prefixItems Schemas for array items by index position
properties Defines schemas for named object properties
propertyNames Schema applied to each property name
required List of required property names
then Schema applied when the if condition is true
type Restricts allowed JSON data types
unevaluatedItems Schema applied to leftover array items
unevaluatedProperties Schema applied to leftover object properties
uniqueItems All items in the array must be unique