JSON Schema Enum: Allowed Values, Examples, and Mistakes

Last updated:

The JSON Schema enum keyword restricts a value to an exact list — validation fails if the input matches none of the allowed values. An enum can mix all 6 JSON types: strings, numbers, booleans, null, arrays, and objects. String-only enums should pair enum with "type": "string" to block accidental numeric coercion. The const keyword is shorthand for a 1-entry enum and produces the same validation result. This guide covers basic string enums with 3–10 values, mixed-type enums, const vs enum tradeoffs, using if/then for conditionally required enum fields, and generating TypeScript union types from an enum schema using json-schema-to-typescript.

Testing enum validation? Paste your schema and sample data into Jsonic's JSON Schema Validator and check rejected values immediately.

Validate JSON Schema

Basic enum example

{
  "type": "object",
  "properties": {
    "status": {
      "type": "string",
      "enum": ["draft", "published", "archived"]
    }
  },
  "required": ["status"]
}

Only those three string values pass. "Draft", "deleted", and null fail.

Enum can contain any JSON value

An enum is not limited to strings. It can include numbers, booleans, null, arrays, and objects, though string enums are the easiest to maintain.

{
  "enum": ["auto", "manual", 0, false, null]
}

Nullable enum

If null is allowed, include it in both the type list and the enum values.

{
  "type": ["string", "null"],
  "enum": ["small", "medium", "large", null]
}

Enum inside arrays

Put enum under items when every array value must come from the same allowed list.

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

Enum vs const

Use enum for multiple allowed values. Use const when exactly one value is allowed.

{
  "type": "object",
  "properties": {
    "type": { "const": "invoice" }
  },
  "required": ["type"]
}

For broader schema examples, see the JSON Schema examples guide.

Common mistakes

MistakeFix
Forgetting enum is case-sensitiveAdd every accepted casing or normalize input first
Allowing null in type but not enumAdd null to the enum array
Using enum for large dynamic listsValidate dynamic IDs in application logic
Putting enum beside an array schemaPut it inside items for array elements

Validate enum values online

Use Jsonic's JSON Schema Validator to test allowed values, nullable enums, and array item enums against sample JSON.

Open Schema Validator

Frequently asked questions

How do I restrict a field to a list of values?

Use the enum keyword inside the property schema: {"type": "string", "enum": ["draft", "published", "archived"]}. Only those exact values pass — comparison is strict and case-sensitive.

Can a JSON Schema enum contain multiple types?

Yes. The enum array can mix strings, numbers, booleans, and null: {"enum": ["auto", 0, false, null]}. When mixing types, omit the type keyword to avoid conflicting constraints.

What is the difference between enum and const?

enum allows a list of values; const allows exactly one. Use const for discriminator fields in oneOf/anyOf schemas where each branch has a unique type identifier.

How do I use enum for status fields?

Define the property with type: "string" and list all valid statuses in enum. Keep statuses lowercase and normalize input before validation, since enum comparison is case-sensitive.

Can enum values be null?

Yes. Include null in both the type array (["string", "null"]) and the enum array. If null is in enum but not in type, some validators will reject it.

What happens if a value is not in the enum list?

The validator reports a validation error listing the allowed values. No exception is made for close matches or case differences — the comparison is exact. The error path points to the failing field.