JSON 没有名称的对象的架构
JSON Schema for objects without names
我想编写验证对象列表的模式的一部分,其中列表中的对象没有名称:
"some list": [
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
]
我有一个工作模式,其中包含我想删除的额外键名称,标记为 I WANT TO GET RID OF THIS NAME
。我想您可能认为它没有 属性 对象的名称。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "v2",
"properties": {
"some list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"I WANT TO GET RID OF THIS NAME": {
"type": "object",
"properties": {
"thing 1": {
"type": "string",
"description": "a string"
},
"thing 2": {
"type": "integer",
"minimum": 0,
"description": "Default time to expose a single image layer for."
}
},
"additionalProperties": false
},
"additionalProperties": false
}
}
}
}
}
我不能 git 删除名称,因为模式规范需要它,但我也不知道如何告诉它那些对象没有名称。我是 运行 这个例子 Python 3.7 使用 jsonschema Draft7Validator
你摆脱那个 属性 是正确的 - 它指的是错误的嵌套级别。架构应如下所示:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "v2",
"properties": {
"some list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"thing 1": {
"type": "string",
"description": "a string"
},
"thing 2": {
"type": "integer",
"minimum": 0,
"description": "Default time to expose a single image layer for."
}
},
"additionalProperties": false
}
}
}
}
我想编写验证对象列表的模式的一部分,其中列表中的对象没有名称:
"some list": [
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
{
"thing 1": "foo",
"thing 2": 100
},
]
我有一个工作模式,其中包含我想删除的额外键名称,标记为 I WANT TO GET RID OF THIS NAME
。我想您可能认为它没有 属性 对象的名称。
{
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "v2",
"properties": {
"some list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"I WANT TO GET RID OF THIS NAME": {
"type": "object",
"properties": {
"thing 1": {
"type": "string",
"description": "a string"
},
"thing 2": {
"type": "integer",
"minimum": 0,
"description": "Default time to expose a single image layer for."
}
},
"additionalProperties": false
},
"additionalProperties": false
}
}
}
}
}
我不能 git 删除名称,因为模式规范需要它,但我也不知道如何告诉它那些对象没有名称。我是 运行 这个例子 Python 3.7 使用 jsonschema Draft7Validator
你摆脱那个 属性 是正确的 - 它指的是错误的嵌套级别。架构应如下所示:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"id": "v2",
"properties": {
"some list": {
"type": "array",
"items": {
"type": "object",
"properties": {
"thing 1": {
"type": "string",
"description": "a string"
},
"thing 2": {
"type": "integer",
"minimum": 0,
"description": "Default time to expose a single image layer for."
}
},
"additionalProperties": false
}
}
}
}