Reference

Enumerated values

The enum keyword is used to restrict a value to a fixed set of values. It must be an array with at least one element, where each element is unique.

The following is an example for validating street light colors:

Copy icon
 logo-white schema
{ "enum": ["red", "amber", "green"]}
Copy icon
data
"red"
Checkmark iconcompliant to schema
Copy icon
data
"blue"
Error iconnot compliant to schema

You can use enum even without a type, to accept values of different types. Let's extend the example to use null to indicate "off", and also add 42, just for fun.

Copy icon
 logo-white schema
{ "enum": ["red", "amber", "green", null, 42]}
Copy icon
data
"red"
Checkmark iconcompliant to schema
Copy icon
data
null
Checkmark iconcompliant to schema
Copy icon
data
42
Checkmark iconcompliant to schema
Copy icon
data
0
Error iconnot compliant to schema

Need Help?

Did you find these docs helpful?

Help us make our docs great!

At JSON Schema, we value docs contributions as much as every other type of contribution!

Still Need Help?

Learning JSON Schema is often confusing, but don't worry, we are here to help!.