| keyword | enum | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| signature | Array<Any> | ||||||||||||||||||||
| value | This keyword must be set to a *non-empty* array of unique JSON values | ||||||||||||||||||||
| summary | Validation succeeds if the instance is equal to one of the elements in this keyword's array value. | ||||||||||||||||||||
| kind |
|
||||||||||||||||||||
| instance |
|
||||||||||||||||||||
| specification | https://json-schema.org/draft-07/draft-handrews-json-schema-validation-01#rfc.section.6.1.2 | ||||||||||||||||||||
| metaschema | http://json-schema.org/draft-07/schema# | ||||||||||||||||||||
| tests |
|
||||||||||||||||||||
| introduced_in | draft1 | ||||||||||||||||||||
| index | -99998 | ||||||||||||||||||||
| related |
|
The [enum]({{< ref "draft7/validation/enum" >}}) keyword restricts instances
to a finite set of possible values, which may be of different types.
{{}} Constraining instances to a set of possible values by
definition implies the given JSON types. Therefore, combining this keyword with
the [type]({{< ref "draft7/validation/type" >}}) keyword is redundant (or
even invalid if types don't agree), and considered an
anti-pattern.{{}}
{{}} There are programming languages, such as JavaScript, that
cannot distinguish between integers and real
numbers. To accommodate for
those cases, JSON Schema considers a real number with a zero fractional part to
be equal to the corresponding integer. For example, in JSON Schema, 1 is
considered to be equal to 1.0.{{}}
{{<schema A schema that constrains instances to an homogeneous string enumeration>}}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [ "red", "green", "blue" ]
}
{{}}
{{<instance-pass A string value that equals a value in the enumeration is valid>}}
"green"
{{}}
{{<instance-fail A string value that does not equal a value in the enumeration is invalid>}}
"black"
{{}}
{{<instance-fail Any other value is invalid>}}
2
{{}}
{{<schema A schema that constrains instances to an homogeneous numeric enumeration>}}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [ 1, 2.0, 3 ]
}
{{}}
{{<instance-pass An integer value that equals a value in the enumeration is valid>}}
1
{{}}
{{<instance-pass An integer representation of a real value that equals a value in the enumeration is valid>}}
2
{{}}
{{<instance-fail Any other number value is invalid>}}
5
{{}}
{{<instance-fail Any other non-number value is invalid>}}
"Hello"
{{}}
{{<schema A schema that constrains instances to an heterogeneous enumeration>}}
{
"$schema": "http://json-schema.org/draft-07/schema#",
"enum": [ "red", 123, true, { "foo": "bar" }, [ 1, 2 ], null ]
}
{{}}
{{<instance-pass A boolean value that equals a value in the enumeration is valid>}}
true
{{}}
{{<instance-pass An object value that equals a value in the enumeration is valid>}}
{ "foo": "bar" }
{{}}
{{<instance-fail An object value that does not equal a value in the enumeration is invalid>}}
{ "foo": "baz" }
{{}}