11---
22title : " Enumerated values"
33section : docs
4- prev :
5- label : Comments
6- url : /understanding-json-schema/reference/comments
7- next :
8- label : Constant values
9- url : /understanding-json-schema/reference/const
104---
115
126The ` enum ` [ keyword] ( ../../learn/glossary#keyword ) is used to restrict a value to a fixed set of values.
@@ -18,16 +12,21 @@ The following is an example for validating street light colors:
1812``` json
1913// props { "isSchema": true }
2014{
21- "enum" : [" red" , " amber" , " green" ]
15+ "properties" : {
16+ "color" : {
17+ "enum" : [" red" , " amber" , " green" ]
18+ }
19+ }
2220}
2321```
2422``` json
2523// props { "indent": true, "valid": true }
26- " red"
24+ { "color" : " red" }
2725```
26+
2827``` json
2928// props { "indent": true, "valid": false }
30- " blue"
29+ { "color" : " blue" }
3130```
3231
3332You can use ` enum ` even without a type, to accept values of different
@@ -37,22 +36,25 @@ also add 42, just for fun.
3736``` json
3837// props { "isSchema": true }
3938{
40- "enum" : [" red" , " amber" , " green" , null , 42 ]
39+ "properties" : {
40+ "color" : {
41+ "enum" : [" red" , " amber" , " green" , null , 42 ]
42+ }
43+ }
4144}
4245```
46+
4347``` json
4448// props { "indent": true, "valid": true }
45- " red"
46- ```
47- ``` json
48- // props { "indent": true, "valid": true }
49- null
49+ { "color" : null }
5050```
51+
5152``` json
5253// props { "indent": true, "valid": true }
53- 42
54+ { "color" : 42 }
5455```
56+
5557``` json
5658// props { "indent": true, "valid": false }
57- 0
58- ```
59+ { "color" : " blue " }
60+ ```
0 commit comments