为什么这个json架构无效?使用“任何”类型

时间:2013-05-30 00:35:48

标签: jsonschema

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "my json api",
    "description": "my json api",
    "type": "object",
    "properties": {
        "my_api_response": {
           "type": "object",
            "properties": {
                "MailboxInfo": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "ADSyncLinkEnabled": {
                                "type": "any"
                            }
                        }
                    }
                }
            }
        }
    },
    "required": ["response"]
}

我正在使用python jsonschema 2.0.0,它给了我以下错误:

{u'type': u'object', u'properties': {u'ADSyncLinkEnabled': {u'type': u'any'}}} is not valid under any of the given schemas

3 个答案:

答案 0 :(得分:15)

这是因为any不再是type关键字的有效值。

如果您想要一个匹配所有内容的架构,只需使用空架构:{}

答案 1 :(得分:1)

您在“必需”之前缺少逗号。

答案 2 :(得分:0)

从json-schema.org文档中,我们发现这与“类型”属性有关:

  

如果它是一个数组,则必须是一个字符串数组,其中每个字符串是一种基本类型的名称,并且每个元素都是唯一的。在这种情况下,如果JSON代码段与任何给定类型匹配,则都是有效的。

因此,实现某种“任意”类型的另一种方法是,您可以包括所有json类型:

"type":["number","string","boolean","object","array", "null"]