You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何基于JSON值移除JSON Schema中的allOf属性

基于JSON值简化带allOf的JSON Schema

原JSON Schema的工作逻辑

  • 当switch字段值为true时,objectDependingOnSwitch对象必须包含一个名为switchIsTrue的字符串类型属性
  • 当switch字段值为false时,objectDependingOnSwitch对象必须包含一个名为switchIsFalse的字符串类型属性

原JSON Schema代码

{
  "type": "object",
  "properties": {
    "switch": {
      "type": "boolean"
    },
    "objectDependingOnSwitch": {
      "type": "object"
    }
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "switch": {
            "const": true
          }
        }
      },
      "then": {
        "properties": {
          "objectDependingOnSwitch": {
            "type": "object",
            "properties": {
              "switchIsTrue": {
                "type": "string"
              }
            }
          }
        }
      }
    },
    {
      "if": {
        "properties": {
          "switch": {
            "const": false
          }
        }
      },
      "then": {
        "properties": {
          "objectDependingOnSwitch": {
            "type": "object",
            "properties": {
              "switchIsFalse": {
                "type": "string"
              }
            }
          }
        }
      }
    }
  ]
}

问题

是否可以基于给定的JSON值移除allOf属性?

举个例子,给定如下JSON值:

{
  "switch": true
}

期望得到简化后的差异化JSON Schema:

{
  "type": "object",
  "properties": {
    "switch": {
      "type": "boolean"
    },
    "objectDependingOnSwitch": {
      "type": "object",
      "properties": {
        "switchIsTrue": {
          "type": "string"
        }
      }
    }
  }
}

内容的提问来源于stack exchange,提问作者Rashomon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.25 07:52:14