Type Validation
type
type
Type: String or Array of stringsPurpose: Constrains the instance to one or more JSON data types.The
type keyword restricts an instance to specific JSON primitive types. It’s one of the most commonly used validation keywords.Valid type values:"null"- JSON null"boolean"- true or false"object"- JSON object"array"- JSON array"number"- any numeric value"string"- string value"integer"- number with zero fractional part
- If a string, instance validates if its type matches the specified type
- If an array, array MUST be non-empty with unique string elements
- If an array, instance validates if its type matches any type in the array
enum
enum
Type: Array (any types)Purpose: Constrains the instance to a fixed set of allowed values.The
enum keyword restricts an instance to one of a predefined list of values using equality comparison.Validation:- Value MUST be an array
- Array SHOULD have at least one element
- Elements SHOULD be unique
- Instance validates if it equals one of the array elements
- Elements may be of any type, including null
const
const
Type: Any JSON valuePurpose: Constrains the instance to a single specific value.The
const keyword is functionally equivalent to enum with a single value, but more clearly expresses the intent.Validation:- Value MAY be of any type, including null
- Instance validates if it equals the keyword’s value
Numeric Validation
These keywords apply only to numeric instances (number and integer types).multipleOf
multipleOf
Type: Number (strictly greater than 0)Purpose: Constrains a numeric instance to be a multiple of the given value.Validation:
- Value MUST be a number strictly greater than 0
- A numeric instance is valid if division by this value results in an integer
- Non-numeric instances are valid (keyword is ignored)
maximum
maximum
Type: NumberPurpose: Constrains a numeric instance to be less than or equal to a maximum value (inclusive upper bound).Validation:
- Value MUST be a number
- If the instance is a number, it validates if it is less than or exactly equal to
maximum - Non-numeric instances are valid
exclusiveMaximum
exclusiveMaximum
Type: NumberPurpose: Constrains a numeric instance to be strictly less than a maximum value (exclusive upper bound).Validation:
- Value MUST be a number
- If the instance is a number, it validates if it is strictly less than
exclusiveMaximum - Non-numeric instances are valid
minimum
minimum
Type: NumberPurpose: Constrains a numeric instance to be greater than or equal to a minimum value (inclusive lower bound).Validation:
- Value MUST be a number
- If the instance is a number, it validates if it is greater than or exactly equal to
minimum - Non-numeric instances are valid
exclusiveMinimum
exclusiveMinimum
Type: NumberPurpose: Constrains a numeric instance to be strictly greater than a minimum value (exclusive lower bound).Validation:
- Value MUST be a number
- If the instance is a number, it validates if it is strictly greater than
exclusiveMinimum - Non-numeric instances are valid
String Validation
These keywords apply only to string instances.maxLength
maxLength
Type: Non-negative integerPurpose: Constrains the maximum length of a string.Validation:
- Value MUST be a non-negative integer
- A string validates if its length is less than or equal to this value
- Length is defined as the number of Unicode code points
- Non-string instances are valid
minLength
minLength
Type: Non-negative integerPurpose: Constrains the minimum length of a string.Validation:
- Value MUST be a non-negative integer
- A string validates if its length is greater than or equal to this value
- Length is defined as the number of Unicode code points
- Omitting this keyword has the same behavior as a value of 0
- Non-string instances are valid
pattern
pattern
Type: String (regular expression)Purpose: Constrains a string to match a regular expression pattern.Validation:
- Value MUST be a string
- String SHOULD be a valid ECMA-262 regular expression
- A string validates if the regex matches the instance successfully
- Regular expressions are NOT implicitly anchored
- Non-string instances are valid
Array Validation
These keywords apply only to array instances.maxItems
maxItems
Type: Non-negative integerPurpose: Constrains the maximum number of items in an array.Validation:
- Value MUST be a non-negative integer
- An array validates if its size is less than or equal to this value
- Non-array instances are valid
minItems
minItems
Type: Non-negative integerPurpose: Constrains the minimum number of items in an array.Validation:
- Value MUST be a non-negative integer
- An array validates if its size is greater than or equal to this value
- Omitting this keyword has the same behavior as a value of 0
- Non-array instances are valid
uniqueItems
uniqueItems
Type: BooleanPurpose: Constrains array items to be unique.Validation:
- Value MUST be a boolean
- If
false, the instance validates successfully - If
true, validates successfully only if all array elements are unique - Elements are equal if they are the same type and value per the data model
- Omitting this keyword has the same behavior as
false - Non-array instances are valid
maxContains
maxContains
Type: Non-negative integerPurpose: Sets the maximum number of array items that can match the
contains schema.Validation:- Value MUST be a non-negative integer
- Modifies the behavior of the
containskeyword in the same schema object - Produces no assertion result on its own
- Used with
containsto create an upper bound
- The value itself is the annotation result
minContains
minContains
Type: Non-negative integerPurpose: Sets the minimum number of array items that must match the
contains schema.Validation:- Value MUST be a non-negative integer
- Modifies the behavior of the
containskeyword in the same schema object - If absent,
containsassumes a minimum of 1 - Produces no assertion result on its own
- The value itself is the annotation result
Object Validation
These keywords apply only to object instances.maxProperties
maxProperties
Type: Non-negative integerPurpose: Constrains the maximum number of properties in an object.Validation:
- Value MUST be a non-negative integer
- An object validates if its property count is less than or equal to this value
- Non-object instances are valid
minProperties
minProperties
Type: Non-negative integerPurpose: Constrains the minimum number of properties in an object.Validation:
- Value MUST be a non-negative integer
- An object validates if its property count is greater than or equal to this value
- Omitting this keyword has the same behavior as a value of 0
- Non-object instances are valid
required
required
Type: Array of stringsPurpose: Specifies which properties must be present in an object.Validation:
- Value MUST be an array
- Array elements MUST be strings and SHOULD be unique
- An object validates if every string in the array is a property name in the instance
- Omitting this keyword has the same behavior as an empty array
- Non-object instances are valid
dependentRequired
dependentRequired
Type: Object (values are arrays of strings)Purpose: Specifies properties that are required when another specific property is present.Validation:
- Value MUST be an object
- Property values MUST be arrays of strings with unique elements
- For each property name appearing in both the instance and this keyword, every string in the corresponding array must also be a property in the instance
- Omitting this keyword has the same behavior as an empty object
- Non-object instances are valid