If-Then-Else (multiple)
- Viewer
 - JSON Schema
 
Loading ....
{
  "type": "object",
  "properties": {
    "street_address": {
      "type": "string"
    },
    "country": {
      "default": "United States of America",
      "enum": [
        "United States of America",
        "Canada",
        "Netherlands"
      ]
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "country": {
            "const": "United States of America"
          }
        }
      },
      "then": {
        "properties": {
          "postal_code": {
            "pattern": "[0-9]{5}(-[0-9]{4})?"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "country": {
            "const": "Canada"
          }
        },
        "required": [
          "country"
        ]
      },
      "then": {
        "properties": {
          "postal_code": {
            "pattern": "[A-Z][0-9][A-Z] [0-9][A-Z][0-9]"
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "country": {
            "const": "Netherlands"
          }
        },
        "required": [
          "country"
        ]
      },
      "then": {
        "properties": {
          "postal_code": {
            "pattern": "[0-9]{4} [A-Z]{2}"
          }
        }
      }
    }
  ]
}