gpt4 book ai didi

json - 确保对象字段的值存在于 Json Schema 的另一个字段中

转载 作者:行者123 更新时间:2023-12-04 15:44:44 24 4
gpt4 key购买 nike

我试图表达对象和它们之间的关系。每个对象都有一个 ID,每个关系都引用 2 个对象 ID。我想确保每个关系都引用现有的对象 ID。你能用 Json Schema 做到这一点吗?

{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"Objects": {
"type": "array",
"items": {
"type": "object",
"properties": {
"id": {
"type": "integer"
}
}
}
},
"Relations": {
"type": "array",
"items": {
"type": "object",
"properties": {
"objId1": {"type": "integer"}, // I'd like these
"objId2": {"type": "integer"} // Two fields to reference an existing Objects.id
}

}
},
},
}

最佳答案

不,你不能用 JSON Schema 做到这一点。对不起。

听起来这是一个数据库。您应该考虑使用数据库级别的约束来进行此类验证。

关于json - 确保对象字段的值存在于 Json Schema 的另一个字段中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56429622/

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