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

如何在JSON Schema中设置字段禁用值(排除特定枚举值)

JSON Schema 排除特定值的解决方案

要实现允许输入除"Orange"之外的任意字符串值,你可以结合type和not关键字来编写规则,之前用not失败大概率是语法结构不对,正确写法如下:

"Car_Color": {
  "type": "string",
  "not": {
    "const": "Orange"
  }
}

规则说明

  • type": "string" 先限定输入必须是字符串类型
  • not 用于否定后续的校验规则,内部用const精准指定要排除的单个值"Orange"

如果后续需要排除多个值,把const换成enum即可:

"Car_Color": {
  "type": "string",
  "not": {
    "enum": ["Orange", "Black"]
  }
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.11 06:30:57