title | section | prev | next | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Enumerated and constant values |
docs |
|
|
The enum
and const
keywords contribute to data validation by defining limits on the values a property can hold.
-
Define a set of values. Use the
enum
keyword to specify a finite set of acceptable values for a property. This ensures that only predefined options are valid. -
Define a fixed, single value. Use the
const
keyword to force a property to have a single, fixed value. This keyword is more restrictive thanenum
.
Learn more about how to use these keywords with the following resources:
By effectively utilizing these keywords, you can significantly enhance the reliability and accuracy of your JSON data.