JSON 验证架构 JSON 具有相同类型项目数组的对象

JSON Schema for validation JSON object with an array of items of the same type

我可以创建 json 模式来验证此对象而不用其他形式重新设计 json 吗?

{      
        "itemColors": {
          "40": "#12ffd6",
          "69": "#f90861",
          "185": "#063ac3"
        },
        "itemVisible": {
          "32": true,
          "33": true,
          "34": true,
          "36": true,
          "37": true,
          "38": true,
          "39": true,
          "40": true,
          "41": true,
          "55": true,
          "56": true,
          "69": true,
          "185": true,
          "187": true,
          "196": true,
          "197": true,
          "198": true
        } 

}

对象可以有不同数量的属性。

ItemColors 的值:

itemVisible 也一样,但值必须是布尔类型

您可以使用 "additionalProperties" 指定未指定属性的架构:

{
   "properties" : {
       "itemColors" : {
            "type" : "object",
            "additionalProperties" : {
                "type" : "string"
            }
       },
       "itemsVisible" : {
            "type" : "object",
            "additionalProperties" : {
                "type" : "boolean"
            }
       }
   }
}

在此处阅读更多内容:https://spacetelescope.github.io/understanding-json-schema/reference/object.html