How to define the two-dimensional array in JSON schema? The problem is that I know, how to define a 2D array with exact items count in a row:
{
type: "array",
items: {
type: "array",
items: {
type: "number",
minItems: 2,
maxItems: 2
}
},
}
But I cannot understand, how to define an array that has exactly the same number of items in each row when this number is not fixed. In other words, I need to define a rectangular shape of a 2D array.
This data should be valid:
[
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
]
and this data also should be valid:
[
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
]
This shouldn't:
[
[1, 2, 3],
[1, 2],
[1, 2, 3],
]
and this shouldn't:
[
[1, 2, 3, 4],
[1, 2, 3],
[1, 2, 3],
]
I don't believe this is possible with JSON Schema because you can't provide dynamic values relating to the instance JSON to the JSON Schema.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With