JSONSchema for "array of objects, they can have any keys, but they all have to have the same keys"

huangapple go评论59阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年2月14日 21:11:39
  • 转载请务必保留本文链接:https://go.coder-hub.com/75448350.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定