Overview
Validation keywords in a schema impose requirements for successful validation of an instance. These keywords are all assertions without any annotation behavior.Any Instance Type
These keywords apply to instances of any type.type
The type keyword validates that an instance matches one of the specified JSON types.
Value: String or array of strings
Valid type values:
"null"- JSON null"boolean"- JSON boolean"object"- JSON object"array"- JSON array"number"- JSON number (including integers and floats)"string"- JSON string"integer"- Any number with a zero fractional part
If
type is an array, the instance validates if its type matches any of the types in the array.enum
The enum keyword validates that an instance value equals one of the specified values.
Value: Array (should have at least one element; elements should be unique)
Elements in the array can be of any type, including
null. The instance must be exactly equal to one of the enum values.const
The const keyword validates that an instance value equals a specific constant value.
Value: Any JSON value, including null
enum with a single value.
Numeric Instances
These keywords apply to instances of typenumber or integer.
multipleOf
Validates that a number is a multiple of the specified value.
Value: Number (must be strictly greater than 0)
Examples
Examples
- Value
10withmultipleOf: 5→ Valid (10 / 5 = 2) - Value
7withmultipleOf: 3→ Invalid (7 / 3 = 2.333…) - Value
1.5withmultipleOf: 0.5→ Valid (1.5 / 0.5 = 3)
maximum
Validates that a number is less than or equal to the specified maximum.
Value: Number
maximum.
exclusiveMaximum
Validates that a number is strictly less than the specified maximum.
Value: Number
exclusiveMaximum.
minimum
Validates that a number is greater than or equal to the specified minimum.
Value: Number
minimum.
exclusiveMinimum
Validates that a number is strictly greater than the specified minimum.
Value: Number
exclusiveMinimum.
String Instances
These keywords apply to instances of typestring.
maxLength
Validates that a string’s length is less than or equal to the specified value.
Value: Non-negative integer
The length of a string is defined as the number of Unicode code points, not bytes or grapheme clusters.
minLength
Validates that a string’s length is greater than or equal to the specified value.
Value: Non-negative integer
0.
pattern
Validates that a string matches a regular expression.
Value: String (should be a valid regular expression)
Array Instances
These keywords apply to instances of typearray.
maxItems
Validates that an array’s size is less than or equal to the specified value.
Value: Non-negative integer
minItems
Validates that an array’s size is greater than or equal to the specified value.
Value: Non-negative integer
0.
uniqueItems
Validates that all elements in an array are unique.
Value: Boolean
- If
true: All array elements must be unique - If
false(or omitted): Duplicate elements are allowed
Object Instances
These keywords apply to instances of typeobject.
maxProperties
Validates that an object’s number of properties is less than or equal to the specified value.
Value: Non-negative integer
minProperties
Validates that an object’s number of properties is greater than or equal to the specified value.
Value: Non-negative integer
0.
required
Validates that an object contains all specified properties.
Value: Array of strings (elements must be unique)
required array is the name of a property in the instance.
dependentRequired
Specifies properties that are required if another specific property is present.
Value: Object where values are arrays of strings
creditCard is present, then billingAddress must also be present.
More Examples
More Examples
Conditional Requirements
Complete Example
Here’s a comprehensive example combining multiple validation keywords:Related Topics
- Format Validation - Semantic format validation
- Annotation Keywords - Meta-data keywords