Skip to content

Commit

Permalink
improve enum doc
Browse files Browse the repository at this point in the history
  • Loading branch information
techmannih committed Jan 14, 2025
1 parent e181398 commit 492558e
Showing 1 changed file with 20 additions and 18 deletions.
38 changes: 20 additions & 18 deletions pages/understanding-json-schema/reference/enum.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
---
title: "Enumerated values"
section: docs
prev:
label: Comments
url: /understanding-json-schema/reference/comments
next:
label: Constant values
url: /understanding-json-schema/reference/const
---

The `enum` [keyword](../../learn/glossary#keyword) is used to restrict a value to a fixed set of values.
Expand All @@ -18,16 +12,21 @@ The following is an example for validating street light colors:
```json
// props { "isSchema": true }
{
"enum": ["red", "amber", "green"]
"properties": {
"color": {
"enum": ["red", "amber", "green"]
}
}
}
```
```json
// props { "indent": true, "valid": true }
"red"
{ "color": "red" }
```

```json
// props { "indent": true, "valid": false }
"blue"
{ "color": "blue" }
```

You can use `enum` even without a type, to accept values of different
Expand All @@ -37,22 +36,25 @@ also add 42, just for fun.
```json
// props { "isSchema": true }
{
"enum": ["red", "amber", "green", null, 42]
"properties": {
"color": {
"enum": ["red", "amber", "green", null, 42]
}
}
}
```

```json
// props { "indent": true, "valid": true }
"red"
```
```json
// props { "indent": true, "valid": true }
null
{ "color": null }
```

```json
// props { "indent": true, "valid": true }
42
{ "color": 42 }
```

```json
// props { "indent": true, "valid": false }
0
```
{ "color": "blue" }
```

0 comments on commit 492558e

Please sign in to comment.