gpt4 book ai didi

jsonschema - 具有随机数键的对象的 JSON 模式

转载 作者:行者123 更新时间:2023-12-05 09:14:20 24 4
gpt4 key购买 nike

我有一个对象,它的键是数字,值是字符串:

{
0: 'blah',
2: 'blah'
}

这个对象是什么,每个键是一个包含错误的数组的索引,字符串描述了那个错误。对于这个模式,我能想到的最接近的是:

{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"0": {
"type": "string"
},
"2": {
"type": "string"
}
},
"required": [
"0",
"2"
]
}

然而,这是不准确的。也许下次只有索引“4”会出错。有没有办法在对象中描述动态键?

最佳答案

您应该尝试 patternProperties。它允许您为名称与给定正则表达式匹配的所有属性定义架构。

{
"patternProperties": {
"^[0-9]+$": {"type": "string"}
}
}

关于jsonschema - 具有随机数键的对象的 JSON 模式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54574530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com