Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a two-dimensional rectangular array in JSON Schema?

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],
]
like image 317
Dolios Avatar asked Feb 12 '26 12:02

Dolios


1 Answers

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.

like image 142
Relequestual Avatar answered Feb 18 '26 13:02

Relequestual



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!