Tao Yu
Tao Yu

Reputation: 25

How to achieve if(or) then condition in JSON schema

I have bunch of enum, and they all have required field, some of then would have same then{}, so I wonder if there is a way to do a "or" inside of if, instead have bunch of if-then.

"if":{
   a or b
},
"then":{
c
}

instead of

"if":{
   a
},
"then":{
c
},
"if":{
   b
},
"then":{
c
}

Upvotes: 0

Views: 44

Answers (1)

Jason Desrosiers
Jason Desrosiers

Reputation: 24489

anyOf is a logical OR operation. You can do something like this.

"if": {
  "anyOf": [a, b]
},
"then": {
  c
}

Upvotes: 1

Related Questions