enum keyword restricts an instance to a fixed set of allowed values.
Syntax
The value ofenum must be an array. This array should have at least one element, and elements should be unique.
Validation Rules
An instance validates successfully if its value is equal to one of the elements in theenum array.
Equality is determined using the rules defined in the JSON Schema Core specification.
Examples
String Values
Numeric Values
Mixed Types
Status Codes
Complex Values
Notes
- Elements in the array can be of any type, including
null - String matching is case-sensitive
- While elements should be unique, duplicate values will be treated as the same constraint
- The
enumkeyword is useful for defining finite sets of valid values like status codes, categories, or configuration options