I am currently in the process of developing a JSON schema that needs to meet the following criteria:
- The schema must declare a top-level object with at least one property
- Each property's value should be an array, with each array containing exactly
N
items - Items within the arrays must be integers within the closed interval
[J, K]
, ornull
- Integer items within each array must be unique
- No uniqueness constraint should be applied to
null
(there should be no relationship betweenN
and the interval sizeK-J
)
While I have successfully satisfied the first 3 requirements and partially met the 4th using the following schema, I am facing challenges with points #4 and #5:
{
"$schema": "http://json-schema.org/draft/2019-09/schema#",
"type": "object",
"minProperties": 1,
"additionalProperties": {
"type": "array",
"minItems": N,
"maxItems": N,
"items": {
"anyOf": [
{
"type": "integer",
"minimum": J,
"maximum": K
},
{
"type": "null"
}
]
},
"uniqueItems": true
}
}
I am seeking guidance on how to impose the uniqueItems
constraint selectively on non-null items within the array. My initial attempts to move uniqueItems
to different levels of the schema did not yield the desired results.
While exploring conditional possibilities, I have not yet determined if this approach will work. I am hopeful that there might be a simpler solution that I have overlooked.
Therefore, my query is: Is there a method to define a JSON schema array where uniqueness is enforced solely on non-null items?