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:

schema
1
{
2
"enum": ["red", "amber", "green"]
3
}
data
1
"red"
compliant to schema
data
1
"blue"
not 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.

schema
1
{
2
"enum": ["red", "amber", "green", null, 42]
3
}
data
1
"red"
compliant to schema
data
1
null
compliant to schema
data
1
42
compliant to schema
data
1
0
not compliant to schema
color openjs foundation logo

Copyright OpenJS Foundation and JSON Schema contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy

© Copyright JSON Schema Organisation 2023