Replies: 1 comment 2 replies
-
I'm not entirely clear what you're trying to do, but I can help explain what your schema is doing and hopefully that will help. To start with let's isolate the part of the schema doing the complex work. The rest is trivial and inconsequential. {
"type": "object",
"unevaluatedProperties": false,
"if": {
"properties": {
"Name": {
"const": "Actual"
}
}
},
"then": {
"properties": {
"Test1": {
"type": "string"
}
}
},
"else": {
"not": {}
}
} To start with, make sure whatever validator you're using supports JSON Schema version 2019-09 or higher. The Here's the "Actual" case. {
"Name": "Actual",
"Test1": "Test1"
} The Now the "Dummy" case. {
"Name": "Dummy"
} The {
"type": "object",
"unevaluatedProperties": false,
"if": { ... },
"then": { ... }
} Now the {
"type": "object",
"properties": {
"Name": { "type": "string" }
},
"unevaluatedProperties": false,
"if": { ... },
"then": { ... }
} Now "Name" is evaluated regardless of whether Now the "Dummy" case with "Test1". {
"Name": "Dummy",
"Test1": "Test1"
} Because the Now the "Test2" case. {
"Name": "Actual",
"Test1": "Test1",
"Test2": "Test2"
} I'm not sure what you're trying to do here, but "Test2" never appears in your schema, so it will always be considered unevaluated. The Now an edge case. {
"Test1": "Test1"
} Because the {
"type": "object",
"properties": { ... },
"unevaluatedProperties": false,
"if": {
...,
"required": ["Name"]
},
"then": { ... }
} Assuming I haven't made any incorrect assumptions about what you're trying to do, that should work if you're using a validator that supports all the keywords used in the schema. |
Beta Was this translation helpful? Give feedback.
-
Hi all,
I have a list of objects. These objects also have a array with objects. The number of the objects of the second list can variate. Depending of a value of a property of this object, I want to evaluate other properties. If all arrays have the same number of objects, everything is fine. If the number of objects changes, no more properties are evaluated with my if/else clause.
I use the following json schema:
My failing json input is the following:
At "Element1" everything works as expected. If the number of elements of the array "Children" changes to two elements. The object with property "name" with value "Actual" is not valid anymore. All following elements will also not be validated again.
With this json input everything works as intended:
Could you kindly advise me?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions