如何在JSON模式中使用任意属性名称
我正在使用JSON数据,其中其中一部分是一个键值对集合,其中键是任意字符串,值是字符串数组。我正在尝试为此编写一个模式,但我不确定如何表示任意属性名称。因此,对于这样的对象:
{
"K1": ["V1", "V2", "V3"],
"K2": ["V4", "V5"],
"K3": ["V6", "V7"]
}
编写具有以下要求的JSON模式的正确方法:
- 必须至少有一个属性。
- 属性可以为其名称具有任何
- 字符串
- 任意
I'm working with JSON data where one portion of it is a key-value pair collection, where the key is an arbitrary string and the value is an array of strings. I'm trying to write a schema for this, but I'm not sure how to represent arbitrary property names. So for an object like this:
{
"K1": ["V1", "V2", "V3"],
"K2": ["V4", "V5"],
"K3": ["V6", "V7"]
}
What would be the right way to write a JSON schema with the following requirements:
- There must be at least one property.
- Properties can have any arbitrary string for their name
- Every property's associated value must be an array of strings
- Every string array must contain at least one string (ie. must not be empty)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以用
statersProperties
来表达属性或属性集的限制模式;它的值是一个模式,它根据匹配的所有属性的值进行评估。因此,例如,要表达一组以大写字母开头的属性的规则,您可以执行“ pattern properties”:{“^[az]”:{...更多规则在这里... 。要根据完整的模式定义属性名称的规则,您可以使用
propertyNames
。为了表达所有属性值的架构,无论名称如何,您都可以使用
fromproperties
。这些规则将与已经与属性匹配的任何属性匹配
或statersproperties
。您可以使用
minproperties
表达最小数量的属性。您可以用
项目
在数组中的所有项目表示规则。Minitems
可用于表达最小允许数量的项目。您的数据架构可以通过:
https schema.org/understanding-json-schema/reference/object.html
https://json-schema.org.org.org.org/underting-json-schema/-json-schema/参考/array.html
You can express a restricted pattern for a property or set of properties with
patternProperties
; its value is a schema, which is evaluated against the values of all properties that match. So for example, to express a set of rules used for properties that start with a capital letter, you can do"patternProperties": { "^[A-Z]": { ... more rules here ...
. To define the rules for a property name in terms of a full schema, you can usepropertyNames
.To express a schema for the value of all properties, regardless of name, you can use
additionalProperties
. These rules will not match against any property already matched with aproperties
orpatternProperties
.You can express the minimum number of properties with
minProperties
.You can express the rules for all items in an array with
items
. AndminItems
can be used to express the minimum allowable number of items.The schema for your data can be expressed by:
https://json-schema.org/understanding-json-schema/reference/object.html
https://json-schema.org/understanding-json-schema/reference/array.html