3

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],
]
Dolios
  • 173
  • 1
  • 6
  • Is there a max size of square matrix that can be sent? If so then you can describe it with brute force oneOf descriptions for every size. – spacether Feb 26 '21 at 15:27

1 Answers1

1

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.

Relequestual
  • 11,631
  • 6
  • 47
  • 83