我正在尝试使用Python和jsonschema模块根据模式验证JSON文件。我的模式是由一系列模式组成的列表,其中一个模式包含基本元素的定义,其余模式则包含这些元素和其他对象的集合。
我找不到加载模式列表的函数文档,以便可以使用它进行验证。我试图将模式分成字典,并在jsonObject上调用适当的模式,但由于它们互相引用,所以这样做不起作用。
如何加载/组装所有模式以进行验证?
我正在尝试加载的模式的一部分:
我找不到加载模式列表的函数文档,以便可以使用它进行验证。我试图将模式分成字典,并在jsonObject上调用适当的模式,但由于它们互相引用,所以这样做不起作用。
如何加载/组装所有模式以进行验证?
我正在尝试加载的模式的一部分:
[{
"definitions": {
"location": {
"required": [
"name",
"country"
],
"additionalProperties": false,
"properties": {
"country": {
"pattern": "^[A-Z]{2}$",
"type": "string"
},
"name": {
"type": "string"
}
},
"type": "object"
}
},
"required": [
"type",
"content"
],
"additionalProperties": false,
"properties": {
"content": {
"additionalProperties": false,
"type": "object"
},
"type": {
"type": "string"
}
},
"type": "object",
"title": "base",
"$schema": "http://json-schema.org/draft-04/schema#"
},
{
"properties": {
"content": {
"required": [
"address"
],
"properties": {
"address": {
"$ref": "#/definitions/location"
}
},
"type": {
"pattern": "^person$"
}
}
}]
JSON对象大概长这样:
{
"type":"person",
"content":{
"address": {
"country": "US",
"name" : "1,Street,City,State,US"
}
}
}