0

What I want to achieve with the example JSON schema below is to apply a condition where if the "name" string is equal to "type1" to require the "settingsType1" array inside the "settings" object and if it is equal to "type2" to require the "settingsType2" object, how can I do that?

{
  "type": "object",
  "properties": {
    "properties": {
      "name": {
        "type": "string",
        "enum": [
          "type1",
          "type2"
        ]
      },
      "settings": {
        "type": "object",
        "properties": {
          "settingsType1": {
            "type": "array"
          },
          "settingsType2": {
            "type": "string"
          }
        }
      }
    }
  }
}
  • Hi, if you can, changing the properties from "name"/"settings" to "Type1", "Type2" and set the correct type for each one would remove the condition. – damorin Nov 25 '22 at 13:01
  • I can't I need this structure. – Jordan Jordanovski Nov 25 '22 at 13:13
  • Have a look at https://stackoverflow.com/questions/38717933/jsonschema-attribute-conditionally-required/38781027#38781027 if you haven't already. The `if`/`then` option should be the best fit for you. If that doesn't help you figure it out, edit your question with your best attempt and I'll write up an answer. – Jason Desrosiers Nov 29 '22 at 19:38

0 Answers0