json架构,用于没有名称的对象

问题描述 投票:0回答:1
我想编写一个验证对象列表的模式的一部分,其中列表中的对象没有名称:

"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

运行此示例
    

您可以摆脱该属性是正确的 - 它是指错误的嵌套水平。模式应该看起来像:
python json schema jsonschema
1个回答
2
投票
{ "$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 } } } }


最新问题
© www.soinside.com 2019 - 2025. All rights reserved.