英文:
JSONSchema for "array of objects, they can have any keys, but they all have to have the same keys"
问题
在JSON模式中,您可以使用"items"
关键字结合"properties"
关键字来指定希望有一个对象数组,而不关心这些对象具有什么键,只要它们具有相同的键。以下是相应的JSON模式:
{
"type": "array",
"items": {
"type": "object",
"properties": {},
"additionalProperties": true
}
}
这个模式指定了一个对象数组,其中每个对象的属性(键)可以为空,而"additionalProperties": true
表示允许任何其他属性。这将允许描述有效的2D数据表,因为它不会强制要求对象具有相同的键。
英文:
Is there a way to specify in a JSON schema that you want an array of objects, you don't care what keys the objects have, as long as they all have the same ones.
Basically, I want a schema that constrains you to describe a valid 2D table of data.
So this would be valid:
[
{"foo": "a", "bar": "b"},
{"foo": "c", "bar": "d"}
]
But this would not:
[
{"foo": "a", "bar": "b"},
{"baz": "c", "bar": "d"}
]
... because the two objects in the array don't share the same keys.
答案1
得分: 2
无法使用标准的JSON Schema规范完成此操作。
英文:
No. You can't do this with the standard JSON Schema specification.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论