不理解有效JSON架构中的此类型定义

不理解有效JSON架构中的此类型定义,json,schema,jsonschema,Json,Schema,Jsonschema,有关猫和狗的定义,请参见: { "Boxes": { "type":"object", "properties": { "Cats": {"type":["integer","null"]}, "Dogs": {"type":["integer","null"]} } } } “type”:[“i

有关
的定义,请参见:

{
  "Boxes": {
        "type":"object",
        "properties":   {
                        "Cats": {"type":["integer","null"]},
                        "Dogs": {"type":["integer","null"]}
                        }
        }
}
“type”:[“integer”,“null”]
施加了什么约束


以下JSON针对该模式进行验证:
{“box”:{“Cats”:[2,3,4,null,“hi”]}
。由于
Cats
包含一个数组,该数组又包含int、strings和null,因此我假设验证会失败。

首先,如果希望数据具有名为
“box”
的顶级属性,则需要将顶级数据定义为具有该属性的对象,例如

{
    "type": "object",
    "properties": {
        "Boxes": {
            "type":"object",
            "properties": {
                "Cats": {"type":["integer","null"]},
                "Dogs": {"type":["integer","null"]}
            }
        }
    }
}
对于您编写的模式,顶级的
“box”
被忽略,因为它不是关键字,所以模式实际上没有任何约束

如果使用上述构造,则
“Cats”
“Dogs”
属性将被约束为整数或
null


不允许使用数组-如果需要数组,则应为这些属性定义
“type”:“array”
,然后使用
项约束数组项

谢谢,但这并不能回答我关于类型声明中数组的功能的问题!或者你是说如果我有盒子的对象声明,验证就会失败?是的,我就是这么说的-我会相应地修改答案。