{ }jsonkitOpen
Schema and validation

const keyword

Also called JSON Schema const, JSON Schema constant

The const keyword in JSON Schema requires a value to equal one fixed constant, such as "const": "invoice". The constant can be any JSON type, and objects or arrays must match exactly, including nested values. It works like a one-item enum and is often used to pin a discriminator field like "type" in a tagged union.

In more detail

The const keyword says that a value must be exactly equal to one constant. It was added in JSON Schema draft 6 and works the same way in later drafts, including 2020-12.

The constant can be any JSON value. Strings and numbers compare by value, and objects and arrays must match exactly, including every nested value. 1 and 1.0 count as equal because they are the same number.

const is a shorter way to write an enum with one item: "const": "invoice" means the same as "enum": ["invoice"]. Its most common use is a discriminator field in a tagged union, where each oneOf branch pins "type" to a different constant so a validator can tell the shapes apart.

Example

A tagged union that uses const on the type fieldjson
{
  "oneOf": [
    {
      "properties": { "type": { "const": "card" }, "last4": { "type": "string" } },
      "required": ["type", "last4"]
    },
    {
      "properties": { "type": { "const": "bank" }, "iban": { "type": "string" } },
      "required": ["type", "iban"]
    }
  ]
}

Try it

Learn more in the guide JSON Schema: a complete guide with examples.

← Back to const keyword in the JSON glossaryUpdated 2026-10-01