Validation
The values authors can enter for a specific property can be constrained using validation keywords.
These validation keywords can be used individually or combined.
They can be used anywhere a value type is defined in the schema, including properties and array items.
Below is a summary of the available validation keywords
Validation Type | Description |
---|---|
Enumerated values | Restricts the value to a fixed set of possible values. Properties using this validation will display as a dropdown.{"enum": ["red", "blue", "green"]} {"enum": [1,2,3]} |
Constant values | Restricts the value to a constant value. Users will be unable to change the value in the authoring interface.{"const": "BannerComponent"} |
Regular expression | Validates the format of text values matches a custom regular expression{"pattern": "[a-z]+"} |
Text minimum length | Validates the minimum length of a text value{"minLength": 1} |
Text maximum length | Validates the maximum length of a text value{"maxLength": 50} |
Text format | Validates the format of text values matches the specified built-in format{"format": "date"} see below for a full list of formats |
Number minimum value | Validates that the value entered is more than or equal to the minimum value.{"minimum": 0} or {"exclusiveMinimum": 0} for just more than |
Number maximum value | Validates that the value entered is less than or equal to maximum value.{"maximum": 10} or {"exclusiveMaximum": 0} for just less than |
Number multiple | Validates that the value entered is a multiple of the multipleOf value{"multipleOf": 2} |
Required properties | Validates that the specified properties must be populated.{"properties": {"name": {"type": "string"}}, "required": ["name"]} |
Array minimum items | Validates that the Array value contains at least the minimum number of items{"minItems": 1} |
Array maximum items | Validates that the Array value does not contain more than the maximum number of items{"maxItems": 1} |
Array unique items | Validates that every item in the Array is unique{"uniqueItems": true} |
GenericLink copied!
Enumerated valuesLink copied!
✅ "small"
❌ "xlarge"
✅ 2
❌ 3
The enum
keyword restricts the values users can select to a fixed list.
Properties using this validation will display as a dropdown.
Constant valuesLink copied!
The const
keyword can be applied to any property to hard-code the value.
Properties using this keyword will be automatically set to the const
value and will be immutable.
StringsLink copied!
Regular ExpressionLink copied!
✅ "summer-sale"
❌ "summer sale"
The pattern
keyword can be applied to any string
property to validate the value matches a custom regular expression.
The pattern
keyword must be a valid ECMA-262 regular expression.
Text Minimum LengthLink copied!
✅ "hello world"
❌ "hello"
The minLength
keyword can be applied to any string
property to validate the number of characters is greater than, or equal to, the value of the keyword.
Text Maximum LengthLink copied!
✅ "hello"
❌ "hello world"
The maxLength
keyword can be applied to any string
property to validate the number of characters is less than, or equal to, the value of the keyword.
Text FormatLink copied!
The format
keyword can be applied to any string
property to validate common data formats that do not have a native JSON representation.
The supported formats are detailed below:
Format | Description |
---|---|
"color" | RGB or RGBA color, e.g. "rgb(255,255,255)" . Will display as a color picker. |
"date" | RFC 3339 Date e.g. "2018-11-20" |
"time" | RFC 3339 Time e.g. "20:20:39" or "20:20:39+00:00" |
"date-time" | RFC 3339 Date-time e.g. "2018-11-13T20:20:39+00:00" |
"markdown" | Markdown rich text, e.g. "# Heading 1" . Will display as a rich text editor. |
"uri" | RFC 3986 URI, e.g. "https://example.com/" |
"uri-reference" | RFC 3986 URI Reference, e.g. "../page" |
"uri-template" | RFC 6570 URI template, e.g. "http://example.com/search{?q,lang}" |
"email" | RFC 5321 Internet email address, e.g. "example@example.com" |
"hostname" | RFC 1123 Hostname, e.g. "example.com" |
"ipv4" | RFC 2673 V4 IP Address, e.g. "192.168.16.1" |
"ipv6" | RFC 2373 V6 IP Address, e.g. "1080:0:0:0:8:800:200C:417A" |
"json-pointer" | RFC 6901 JSON Pointer, e.g. "/foo/bar" |
"relative-json-pointer" | Relative JSON Pointer, e.g. "0#" |
"regex" | ECMA 262 Regular expression, e.g. "[a-z]+" |
NumbersLink copied!
Minimum valueLink copied!
✅ 0
❌ -1
✅ 1
❌ 0
The minimum
keyword can be applied to any number
property to validate the value is greater than, or equal to, the value of the keyword.
The exclusiveMinimum
keyword can be applied to any number
property to validate the value is greater than the value of the keyword.
Maximum valueLink copied!
✅ 100
❌ 101
✅ 99
❌ 100
The maximum
keyword can be applied to any number
property to validate the value is less than, or equal to, the value of the keyword.
The exclusiveMaximum
keyword can be applied to any number
property to validate the value is less than the value of the keyword.
MultipleLink copied!
✅ 4
❌ 3
The multipleOf
keyword can be applied to any number
property to validate the value is a multiple of the value of the keyword.
ObjectsLink copied!
Required PropertiesLink copied!
✅ {"title": "Summer Dress", "sku": "xa83748"}
❌ {"title": "Summer Dress"}
❌ {"sku": "xa83748"}
The required
keyword can be applied to any object
property to validate the specified properties are populated.
The required
keyword must be an array containing a unique set of property names, which must correspond to a property defined in the properties
object.
ArraysLink copied!
Array minimum itemsLink copied!
✅ ["item 1", "item 2", "item 3"]
✅ ["item 1", "item 2"]
❌ ["item 1"]
The minItems
keyword can be applied to any array
property to validate the length of the array is greater than, or equal to, the value of the keyword.
Array maximum itemsLink copied!
✅ ["item 1"]
✅ ["item 1", "item 2"]
❌ ["item 1", "item 2", "item 3"]
The maxItems
keyword can be applied to any array
property to validate the length of the array is less than, or equal to, the value of the keyword.
Array unique itemsLink copied!
✅ ["item 1", "item 2"]
❌ ["item 1", "item 1"]
The uniqueItems
keyword can be applied to any array
property to validate the items inside the array are unique.