Reference
Enumerated values
The enum
keyword in JSON Schema allows you to restrict a value to a set of predefined options.
It requires an array with at least one unique element, and any value validated against this schema must exactly match one of the specified values.
Below are several examples demonstrating its usage.
Basic Example: Street Light Colors
This example demonstrates how to validate that the color
property of a street light is either "red", "amber", or "green".
Extended Example: Accepting Multiple Data Types
Enums 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.
Additional Example: Mixed Types for Shape
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!.