Liquid XML Studio 2019
If Then Else
JSON Schema Editor > Graphical Notation Overview > If Then Else
Draft 04 Draft 06 Draft 07

 The 3 properties If, Then, Else make it possible to specify conditional validation rules for a schema. Each of them contains a JSON Schema.

The schema described within the If clause is evaluated against the value in the JSON Instance Document.

If a schema contains a Then or Else with no If, then the Then or Else will be ignored.

Example JSON Schema
Copy Code
"Value": {
    "type": [
    "if": {
        "type": "integer"
    "then": {
        "type": "integer",
        "maximum": 9999,
        "minimum": 0
    "else": {
        "type": "string",
        "maxLength": 4,
        "minLength": 1,
        "pattern": "\\d+"

The schema describes a property called "Value" which can contain a string or a Number.

If the value in the instance document is an integer, then the rules in the Then are applied meaning it must be in the range 0-9999.

If the value is not an integer then it must be a string 1-4 chars long matching the regex pattern "\d+".

Example Valid JSON Instance Document Fragments
Copy Code
"Value" : "1234"

"Value" : 1234

"Value" : "0"
Example Invalid JSON Instance Document Fragments
Copy Code
"Value" : ""

"Value" : 100000

"Value" : "FRED"

See Also