JSON & Schema

JSON Schema enum: Allowed Values and Examples

The enum keyword accepts a value only when it is deeply equal to one item in the declared list. The items may be strings, numbers, booleans, null, arrays, or objects.

Published

JSON Schema enum example

Schema:

{
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "enum": ["active", "pending", "disabled"]
    }
  },
  "required": ["status"]
}

Valid

{ "status": "active" }

Invalid

{ "status": "deleted" }

"deleted" is not in the enum list, so validation fails.

Test this enum in JSON Schema Validator →

What the enum keyword does

Validation succeeds when the instance equals one of the listed JSON values. Comparisons are case-sensitive and preserve JSON types.

{ "type": "string", "enum": ["active", "pending", "disabled"] }

Strings, numbers, booleans and null

Enum values are JSON values, not labels. The number 1, string "1", boolean true, and null are four different choices.

{ "enum": [1, "1", true, null] }

How to allow null in a JSON Schema enum

When a schema declares both type and enum, a value must satisfy both. To allow null here, include "null" in the allowed types and the JSON value null in enum. Adding it to only one constraint is not enough.

{
  "type": ["string", "null"],
  "enum": ["active", "pending", null]
}

enum inside object properties

{
  "type": "object",
  "properties": { "status": { "enum": ["active", "pending"] } },
  "required": ["status"]
}

To control extra keys alongside allowed values, configure additionalProperties.

JSON Schema enum inside an array

Place enum inside items when every array element must belong to a fixed list. For example, ["read", "write"] is valid, while ["read", "admin"] fails because "admin" is not an allowed item.

{
  "type": "array",
  "items": {
    "type": "string",
    "enum": ["read", "write", "delete"]
  }
}

See the JSON Schema Array guide for more ways to constrain array items and the collection itself.

enum vs const

KeywordUse it whenExample
enumSeveral values are acceptedactive | pending
constExactly one value is acceptedkind = user

If allowed values vary between schema branches, compare oneOf, anyOf and allOf to choose how those branches combine.

Case sensitivity and common mistakes

  • Active and active are different strings.
  • enum does not make a property required.
  • Numeric and string representations are not interchangeable.
  • A generator cannot discover every future allowed value from one sample.

Generate, refine and validate

Generate the structural baseline from representative samples, add the approved enum deliberately, then validate both accepted and rejected values in JSON Schema Validator.

Frequently asked questions

How do I use enum in JSON Schema?

Add enum with the allowed JSON values. A value passes only if it matches an entry and satisfies the other schema constraints.

{ "type": "string", "enum": ["active", "pending"] }

Can a JSON Schema enum contain numbers, booleans, or null?

Yes. enum accepts JSON values and is not limited to strings. The example allows those three values. If type is also specified, it must permit their types.

{ "enum": [1, true, null] }

What is the difference between enum and const in JSON Schema?

enum defines a list of allowed values; const allows exactly one value. Use enum for several choices and const for a single fixed value.

Try the example

Generate a base schema from observed status data

Start with the real object shape before adding a deliberate enum constraint.

{"status":"active","role":"admin"}

Expected result: The generator infers string properties; it does not invent unobserved allowed values.

Try the example

Reject a value outside enum

Validate an archived status against the approved status list.

enum: [active, pending, disabled]
value: archived

Expected result: Validation fails at /status because archived is not an allowed value.

Start from real JSON

Generate a base schema

Infer the structural schema, then add the enum values your application actually permits.

Open JSON to JSON Schema Generator →