Jsonschema xxx不是对象类型

时间:2019-11-22 10:06:13

标签: python-3.x jsonschema

我使用python和json模式作为数据验证器工具,以下是我的模式:

    ValidatorSchema = {
        "type": "object",
        "required": ["data"],
        "properties": {
            "data":
                {
                    "type": "object",
                    "required": ["account", "password", "clientType"],
                    "properties": {
                        "account": {
                            "type": "string"
                        },
                        "password": {
                            "type": "string"
                        },
                        "clientType": {
                            "type": "integer",
                            "enum": [ClientTypeEnum.USER_EMAIL.code, ClientTypeEnum.USER_MOBILE.code,
                                     ClientTypeEnum.USER_MINA.code,
                                     ClientTypeEnum.USER_WECHAT.code]
                        }
                    }
                }
        }
    }

和我的数据:

{
    "data": {
        "account": "ccl",
        "password": "12345678",
        "level": 0,
        "client_type": 100
    }
}

但是验证器总是向我显示错误,我该如何解决:

SchemaError: b'{\n    "data": {\n        "account": "ccl",\n        "password": "12345678",\n        "level": 0,\n        "client_type": 100\n    }\n}' is not of type 'object'

1 个答案:

答案 0 :(得分:0)

您的模式表明必须填写以下字段:

["account", "password", "clientType"]

但是,您的json具有:

{
    "account": "ccl",
    "password": "12345678",
    "client_type": 100 
}

您能发现差异吗?