Conditional

Schema template

Try in Validator

JSON Schema

{
  "type": "object",
  "properties": {
    "kind": {
      "enum": [
        "company",
        "person"
      ]
    },
    "taxId": {
      "type": "string"
    },
    "birthDate": {
      "type": "string",
      "format": "date"
    }
  },
  "if": {
    "properties": {
      "kind": {
        "const": "company"
      }
    }
  },
  "then": {
    "required": [
      "taxId"
    ]
  },
  "else": {
    "required": [
      "birthDate"
    ]
  }
}

Valid example JSON

{
  "kind": "company",
  "taxId": "US-123"
}

Invalid example JSON

{
  "kind": "company",
  "birthDate": "2000-01-01"
}

Fields

FieldTypeRequiredDescription
ifschemaYesCondition schema evaluated first.
thenschemaNoApplied when if matches.
elseschemaNoApplied when if does not match.

How to use this schema

Use conditional schemas for discriminated forms and API payloads where one field changes which other fields are required. Check draft support before relying on it.

Version support and combinations

This keyword or pattern is commonly supported across modern JSON Schema workflows. Check your validator for Draft-04, Draft-07, 2019-09, and 2020-12 behavior before relying on newer composition or conditional features.

Common combination: pair this reference with type, required, and properties so validation errors are specific enough for API clients and form users.

Batch validation seed

Want to validate JSON Schema in bulk? Toolumina Pro can grow into batch validation for 100+ files, saved schemas, and repeatable API contract checks.