Skip to main content
Advanced validation rules let you react to contextual data, enforce dependencies between properties, and design predictable nested schemas.

Conditional rules

Use the when clause to activate a rule only if a condition evaluates to true. The condition uses the same operators as the search DSL on the profile’s property paths.
{
  "properties": {
    "practiceNumber": { "type": "integer" },
    "specialties": {
      "type": "array",
      "rules": [
        {
          "required": true,
          "min": 1,
          "when": {
            "eq": {
              "practiceNumber": "*"
            }
          }
        }
      ],
      "items": { "type": "symbol" }
    }
  }
}

Supported operators

OperatorDescription
eqChecks equality. Use * as a wildcard to test for presence.
ltValid for numeric or temporal fields to enforce “less than or equal.”
gtValid for numeric or temporal fields to enforce “greater than or equal.”
Combine multiple rules in the same array to express complex validation logic.

Nested objects

when clauses reference properties from the root of the profile. For nested structures, use dot notation:
{
  "properties": {
    "details": {
      "type": "object",
      "properties": {
        "contact": {
          "type": "contactpoint",
          "properties": {
            "system": {
              "rules": [
                {
                  "required": true,
                  "enum": ["phone", "fax", "email"]
                }
              ]
            }
          }
        },
        "emailCC": {
          "type": "symbol",
          "rules": [
            {
              "required": true,
              "when": {
                "eq": {
                  "details.contact.system": "email"
                }
              }
            }
          ]
        }
      }
    }
  }
}

Arrays of objects

When validating within arrays, you can target:
  • Any element — Refer to the property directly (for example, contacts.system).
  • The current element — Use [current] to reference the object that is currently being validated.
{
  "properties": {
    "contacts": {
      "type": "array",
      "items": {
        "type": "contactpoint",
        "properties": {
          "value": {
            "rules": [
              {
                "required": true,
                "when": {
                  "eq": {
                    "contacts[current].system": "email"
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}

Cardinality

Cardinality expresses how many instances of a property are allowed within a complex type.
NotationNameDescriptionValidation
0:1Zero to oneOptional property, maximum one valueProperty can be omitted or appear once
1:1One to oneRequired property, exactly one valueMissing or duplicate values fail validation
0:*Zero to manyOptional property, unlimited values (arrays)Property can be omitted or contain any number of elements
1:*One to manyRequired property, at least one value (arrays)Enforces a non-empty array
{
  "patientName": {
    "family": "Wilson",              // 0:1
    "given": ["Sarah", "Elizabeth"], // 0:*
    "use": "official"                // 0:1
  }
}
Cardinality rules are enforced during validation. Missing required properties or over-populated single-valued properties will fail ingestion.

Continue with vocabulary binding to link fields to controlled concept sets.
I