Skip to main content
Use const to pin a field to a single allowed value.

Basic usage

{
  "type": "object",
  "properties": {
    "version": { "const": "v1" }
  },
  "required": ["version"],
  "additionalProperties": false
}

Discriminator pattern

const is commonly used to tag branches in oneOf/anyOf schemas.
{
  "oneOf": [
    {
      "type": "object",
      "properties": {
        "action": { "const": "search" },
        "query": { "type": "string" }
      },
      "required": ["action", "query"],
      "additionalProperties": false
    },
    {
      "type": "object",
      "properties": {
        "action": { "const": "lookup" },
        "id": { "type": "integer" }
      },
      "required": ["action", "id"],
      "additionalProperties": false
    }
  ]
}