0

I have this example JSON:

{
"possible_choices": ["one", "two", "three"],
"active_choice": "two"
}

How can I ensure that active_choice can only be one of the possible_choices using JSONSchema?

Basically, I want it to behave as if it is an enum, but values are dynamically picked up from another array property!

Saw
  • 6,199
  • 11
  • 53
  • 104
  • Pls show us what you have tried so far and what is the problem? – Serge Aug 20 '22 at 17:39
  • I have searched for such an option and didn't find any way of doing it, it might not even be possible but I thought I ask this great community before I give up! – Saw Aug 21 '22 at 20:47
  • Does this answer your question? [Express that, for a given property value, a property with the same name should exist using json schema?](https://stackoverflow.com/questions/55691332/express-that-for-a-given-property-value-a-property-with-the-same-name-should-e) – Relequestual Sep 01 '22 at 08:46

1 Answers1

1

It is not possible to check against values that are unknown at time of schema definition. You need the specific values or at least the pattern they adhere to at time of schema definition.

To achieve the validation you're looking for you will need to implement it on your own on top of JsonSchema.

Byted
  • 579
  • 2
  • 12
  • Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Aug 28 '22 at 03:37