gpt4 book ai didi

json - 使用 json 模式强制对象非空

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

我们可以强制类型对象的空属性如下:

{
"description": "voice mail record",
"type": "object",
"additionalProperties": false,
"properties": {}
}

如解释 here .

现在我想验证属性
  • 是对象类型,
  • 没有任何预定义的属性
  • 可以具有字符串或数字类型的属性
  • 不应为空

  • 强制非空(第 4 点)是我无法猜测的。这与上面示例中的强制空性有些相反。我当前的 json 模式摘录如下所示:
    "attribute": 
    {
    "type": "object",
    "additionalProperties": { "type": ["string","number","integer"] }
    }

    但上面并不强制非空。我怎样才能做到这一点?

    最佳答案

    听起来像 minProperties 是你想要的。

    {
    "type": "object",
    "additionalProperties": {"type": ["string", "number", "integer"]},
    "minProperties": 1
    }

    还有 maxProperties ,它可以用作您链接到的相反问题的替代解决方案。

    关于json - 使用 json 模式强制对象非空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35651589/

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