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.
Below are several examples demonstrating its usage.
Basic Example: Street Light ColorsThis example demonstrates how to validate that the color
property of a street light is either "red", "amber", or "green".
{ "properties": { "color": { "enum": ["red", "amber", "green"] } }}
compliant to schema
not compliant to schema
Extended Example: Accepting Multiple Data TypesEnums can be used without explicitly setting a data type, allowing different types of values. In the following example, the schema is extended to include null
(to represent an "off" state) and the number 42.
{ "properties": { "color": { "enum": ["red", "amber", "green", null, 42] } }}
compliant to schema
compliant to schema
not compliant to schema
Additional Example: Mixed Types for Shape schema{ "properties": { "shape": { "enum": ["circle", "square", 1, null] } }}
compliant to schema
compliant to schema
compliant to schema
not 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!.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4