如何在JSON模式中定义二维矩形数组? [英] How to define a two-dimensional rectangular array in JSON Schema?
本文介绍了如何在JSON模式中定义二维矩形数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在JSON模式中定义二维数组?问题是,我知道如何定义一个具有精确项目数的2D数组:
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.
此数据应有效:
[
[1, 2, 3],
[1, 2, 3],
[1, 2, 3],
]
此数据也应有效:
[
[1, 2, 3, 4],
[1, 2, 3, 4],
[1, 2, 3, 4],
]
这不应该:
[
[1, 2, 3],
[1, 2],
[1, 2, 3],
]
这不应该:
[
[1, 2, 3, 4],
[1, 2, 3],
[1, 2, 3],
]
推荐答案
我不认为这对于JSON Schema是可行的,因为您无法向JSON Schema提供与实例JSON相关的动态值.
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.
这篇关于如何在JSON模式中定义二维矩形数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文