Reputation: 184
I have a payload that i want to validate using JSON schema, but there this case that i don't know how to translate to a schema.
Let's say i have this object:
{
jobs: [
{ title: "Developer", salary: "100", actual: false },
{ title: "Plumber", salary: "200", actual: true },
{ title: "Teacher", salary: "100", actual: false }
]
}
i want to write a schema that validates that IF there are objects in the jobs
array, one (and only one) of them MUST have the actual
key set to true
.
Is this possible?
Upvotes: 1
Views: 1103
Reputation: 54014
Yes, it's possible. You want to set up a schema with the "items", "contains", "minContains" and "maxContains" keywords that leverage the "if"/"then" ability to write conditionals. That is, in pseudocode:
Upvotes: 1