---
canonical: https://amplience.com/developers/docs/schema-reference/conditionals/
title: Conditionals

description: Use the Amplience schema reference conditional support to set the state and value of one or more properties of a schema using if/then/else syntax
audience: Developer
date_published: 2026-05-07
date_modified: 2026-06-02
---

# Conditionals

Conditionals (if/ then/ else) allow you to set the state and value of one or more properties in a schema, based on the state of another property. For example, you can use conditionals to enable or disable a property based on a user selection, or hide or show one or a group of properties.

On this page we've provided examples of some of the common uses for conditionals. See [conditionals- schema examples](https://amplience.com/developers/docs/schema-reference/schema-examples/core-concepts/conditionals/#conditionals-example-one) for more.

> **Info:** We don't currently support all of the features specified in the [JSON schema conditionals reference](https://json-schema.org/understanding-json-schema/reference/conditionals#). In particular, wrapping *multiple* if/then conditions inside `allOf` is not supported. However using [content palettes with objects](https://amplience.com/developers/docs/schema-reference/content-palettes/#content-palette--object) does provide an alternative way to structure your schema to support choosing one from a number of options.

## Hiding and showing properties

In this example the `date` property is shown or hidden based on the state of the `hasDate` boolean.

```json
{
   "$schema":"http://json-schema.org/draft-07/schema#",
   "$id":"https://examples.com/conditionals-example",
   "title":"Conditionals example",
   "description":"Conditionals- date shown on checkbox selected",
   "allOf":[
      {
         "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content"
      }
   ],
   "type":"object",
   "properties":{
      "event":{
         "title":"Event",
         "description":"Our client meetings",
         "type":"object",
         "properties":{
            "title":{
               "title":"Event Name",
               "type":"string"
            },
            "hasDate":{
               "type":"boolean"
            }
         },
         //highlight-start
         "if":{
            "properties":{
               "hasDate":{
                  "const":false
               }
            }
         },
         "then":{
            
         },
         "else":{
            "properties":{
               "date":{
                  "type":"string",
                  "format":"date"
               }
            }
         }
       //highlight-end
      }
   },
   "propertyOrder":[
      
   ]
}
```

## Hiding and showing properties based on validation

In the following example `additionalNotes` is shown if the `email` property is a valid email address, according to the regular expression defined in the `pattern`.

```json
{
   "$schema":"http://json-schema.org/draft-07/schema#",
   "$id":"https://example.com/conditional-pattern",
   "title":"Conditional Example",
   "description":"Conditional Example",
   "allOf":[
      {
         "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content"
      }
   ],
   "type":"object",
   "properties":{
      "email":{
         "type":"string"
      }
   },
   "if":{
      "properties":{
         "email":{
            "type":"string",
            "title":"Email address",
            "pattern":"^[a-z0-9][-a-z0-9._]+@([-a-z0-9]+\\.)+[a-z]{2,5}$"
         }
      },
      "required":[
         "email"
      ]
   },
   "then":{
      "properties":{
         "additionalNotes":{
            "type":"string",
            "title":"Additional notes",
            "ui:component":{
               "name":"text-area"
            }
         }
      }
   }
}
```

## Conditional validation

In the example shown below, the `country` property is used to determine the validation used for the `addressCode` property. Different validation is used for a UK or US address.

```json
{
   "$schema":"http://json-schema.org/draft-07/schema#",
   "$id":"https://examples.com/conditional-validation",
   "title":"Conditional validation",
   "description":"Validation set on country selection",
   "allOf":[
      {
         "$ref":"http://bigcontent.io/cms/schema/v1/core#/definitions/content"
      }
   ],
   "type":"object",
   "properties":{
      "addresssValidation":{
         "type":"object",
         "title":"Address validation",
         "properties":{
            "country":{
               "type":"string",
               "title":"Choose Country",
               "default":"uk",
               "oneOf":[
                  {
                     "const":"uk",
                     "title":"United Kingdom"
                  },
                  {
                     "const":"us",
                     "title":"United States"
                  }
               ]
            }
         },
         //highlight-start
         "if":{
            "properties":{
               "country":{
                  "const":"uk"
               }
            }
         },
         "then":{
            "properties":{
               "addressCode":{
                  "type":"string",
                  "title":"Post Code",
                  "pattern":"^[A-Z]{1,2}[0-9][0-9A-Z]? [0-9][A-Z]{2}$"
               }
            }
         },
         "else":{
            "properties":{
               "addressCode":{
                  "type":"string",
                  "title":"Zip code",
                  "pattern":"^[0-9]{5}(?:-[0-9]{4})?$"
               }
            }
         }
        //highlight-end
      }
   },
   "propertyOrder":[
      
   ]
}
```
