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:
1
{2
"enum": ["red", "amber", "green"]3
}data
1
"red"data
1
"blue"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.
1
{2
"enum": ["red", "amber", "green", null, 42]3
}data
1
"red"data
1
nulldata
1
42data
1
0Need help?
Learning JSON Schema is often confusing, but don't worry, we are here to help! You can start a thread on GitHub Discussions, connect with us on Slack, or join our live Office Hours.
We'd love to help!! ❤️