Python 验证失败';类型';json模式
我已经编写了一小部分os json模式,但使用python jsonschema时出现了一个验证错误 这是我的模式:Python 验证失败';类型';json模式,python,json,Python,Json,我已经编写了一小部分os json模式,但使用python jsonschema时出现了一个验证错误 这是我的模式: { "$schema": "http://json-schema.org/draft-04/schema#", "definitions": { "output": { "type": "object", "properties": { "Type": { "type": "object",
{
"$schema": "http://json-schema.org/draft-04/schema#",
"definitions": {
"output": {
"type": "object",
"properties": {
"Type": {
"type": "object",
"properties": {
"Type": {
"type": "string"
},
"Value": {
"type": "string"
},
"Default": {
"type": "string"
},
"Description": {
"type": "string"
},
"Options": {
"type": "array"
}
},
"required": [
"Type",
"Value",
"Default",
"Description",
"Options"
]
},
"Inverted": {
"type": "object",
"properties": {
"Type": {
"type": "string"
},
"Value": {
"type": "bool"
},
"Default": {
"type": "bool"
},
"Description": {
"type": "string"
}
},
"required": [
"Type",
"Value",
"Default",
"Description"
]
},
"Pulse Width": {
"type": "object",
"properties": {
"Type": {
"type": "string"
},
"Value": {
"type": "number"
},
"Default": {
"type": "number"
},
"Description": {
"type": "string"
}
},
"required": [
"Type",
"Value",
"Default",
"Description"
]
}
},
"required": [
"Type",
"Inverted",
"Pulse Width"
]
}
}
}
以下是我收到的错误:
Failed validating u'type' in schema
我正在尝试使用以下内容验证我的架构:
schema = ""
with open(jsonSchemaFilePath, 'r') as schema_file:
schema = schema_file.read()
try:
Draft4Validator.check_schema(schema)
except SchemaError as schemaError:
print schemaError
我写的模式有什么错?不允许我有名为Type的属性吗?我的问题是
Draft4Validator。check\u schema
接受dic
而不是字符串,也不是json对象
以下是我的解决方案:
schema = {}
with open(jsonSchemaFilePath, 'r') as schema_file:
schema = json.loads(schema_file.read())
try:
Draft4Validator.check_schema(schema)
except SchemaError as schemaError:
print schemaError
我之前的评论是不正确的。我试着把你的JSON加载到我的shell中,效果很好。
check\u schema
是否需要json对象?check\u schema
正在寻找dic
很高兴您找到了它。你应该把你的答案标记为正确!刚刚做了:-)不得不等几天。。。谢谢你的提醒!