0

For example, if I have a json object like this:

{
  "people":[
     {"id":"a","name":"a","gender":"m"},
     {"id":"b","name":"b","gender":"f"},
     {"id":"c","name":"c","gender":"f"},
     {"id":"d","name":"d","gender":"m"}
],
 "over21":[
      "a",
      "c"
 ]
}

and I would like to validate that every name in the over21 array exist in the people array. Using $ref didn't solve the problem because it validates its type, but not its existence elsewhere.

example of a json that should fail validation (since "e" does not exist):

{
  "people":[
     {"id":"a","name":"a","gender":"m"},
     {"id":"b","name":"b","gender":"f"},
     {"id":"c","name":"c","gender":"f"},
     {"id":"d","name":"d","gender":"m"}
],
 "over21":[
      "a",
      "e"
 ]
}
Zack S
  • 1,412
  • 1
  • 23
  • 37

1 Answers1

0

Take a look at "enumerated values" here. I'm sure this can help you. First time answering so if this isn't helpful, I'm sorry.

begprog
  • 271
  • 1
  • 2
  • 8
  • First of all, thank you for taking the time and responding to my question! ENUM is a different use case which allows you to specify (and hard code) all the possible options. I'm looking for something more "dynamic" that will allow enum coming from the document itself (as mentioned in my listed question) – Zack S Apr 16 '19 at 21:00