Skip to main content
JSON Forms supports advanced JSON Schema features for building sophisticated forms with conditional logic and complex data structures.

oneOf - Type Selection

The oneOf keyword allows users to choose between different schema alternatives. This is useful for polymorphic data.
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" }
      },
      "required": ["street_address", "city", "state"],
      "additionalProperties": false
    },
    "user": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "mail": { "type": "string" }
      },
      "required": ["name", "mail"],
      "additionalProperties": false
    }
  },
  "type": "object",
  "properties": {
    "name": { "type": "string" },
    "addressOrUser": {
      "oneOf": [
        { "$ref": "#/definitions/address" },
        { "$ref": "#/definitions/user" }
      ]
    }
  },
  "required": ["name"]
}
JSON Forms automatically renders a dropdown to select between the address and user schemas.

anyOf - Multiple Valid Types

The anyOf keyword is similar to oneOf but allows data to match multiple schemas simultaneously.
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    },
    "user": {
      "type": "object",
      "properties": {
        "name": { "type": "string" },
        "mail": { "type": "string" }
      },
      "required": ["name", "mail"]
    }
  },
  "type": "object",
  "properties": {
    "addressOrUser": {
      "anyOf": [
        { "$ref": "#/definitions/address" },
        { "$ref": "#/definitions/user" }
      ]
    }
  }
}

allOf - Schema Composition

The allOf keyword combines multiple schemas, useful for extending base schemas with additional properties.
{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street_address": { "type": "string" },
        "city": { "type": "string" },
        "state": { "type": "string" }
      },
      "required": ["street_address", "city", "state"]
    }
  },
  "type": "object",
  "properties": {
    "billing_address": {
      "$ref": "#/definitions/address"
    },
    "shipping_address": {
      "allOf": [
        { "$ref": "#/definitions/address" },
        {
          "type": "object",
          "properties": {
            "type": {
              "type": "string",
              "enum": ["residential", "business"]
            }
          },
          "required": ["type"]
        }
      ]
    }
  }
}
The shipping address includes all properties from the base address schema plus the additional type field.

Rules - Conditional Rendering

Rules enable dynamic form behavior based on data values. Use rules to show, hide, enable, or disable form elements.
{
  "type": "object",
  "properties": {
    "name": {
      "type": "string"
    },
    "dead": {
      "type": "boolean"
    },
    "kindOfDead": {
      "type": "string",
      "enum": ["Zombie", "Vampire", "Ghoul"]
    },
    "vegetables": {
      "type": "boolean"
    },
    "kindOfVegetables": {
      "type": "string",
      "enum": ["All", "Some", "Only potatoes"]
    }
  }
}

Rule Effects

  • SHOW: Shows the element when condition is true
  • HIDE: Hides the element when condition is true
  • ENABLE: Enables the element when condition is true
  • DISABLE: Disables the element when condition is true

Rule Conditions

Conditions use JSON Schema to test data values:
{
  "rule": {
    "effect": "SHOW",
    "condition": {
      "scope": "#/properties/provideAddress",
      "schema": { "const": true }
    }
  }
}
You can also use more complex schemas:
{
  "condition": {
    "scope": "#/properties/age",
    "schema": {
      "type": "number",
      "minimum": 18
    }
  }
}

Schema References

Use $ref to reuse schema definitions and keep your schemas DRY:
{
  "definitions": {
    "address": {
      "type": "object",
      "properties": {
        "street": { "type": "string" },
        "city": { "type": "string" }
      }
    }
  },
  "type": "object",
  "properties": {
    "billingAddress": { "$ref": "#/definitions/address" },
    "shippingAddress": { "$ref": "#/definitions/address" }
  }
}

Best Practices

  • Use oneOf when the user must choose exactly one type
  • Use anyOf when multiple schemas can apply simultaneously
  • Use allOf to extend base schemas with additional properties
  • Use rules for dynamic form behavior instead of conditional schemas when possible
  • Keep schema definitions reusable with $ref
  • Use additionalProperties: false with oneOf/anyOf to help JSON Forms distinguish between alternatives
  • Provide clear titles in oneOf/anyOf definitions for better user experience

Next Steps

  • Learn more about Rules for advanced conditional logic
  • Explore Custom Renderers to handle specialized schema patterns
  • See Validation for custom validation logic

Build docs developers (and LLMs) love