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

如何在文档数组的JSON Schema中添加独立的requestID字段?

修改后的JSON Schema

你需要把顶层结构从数组改成对象,这样就能同时包含独立的requestID字段和文档数组了。下面是调整后的完整Schema:

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "requestID": {
      "type": "string"
    },
    "documents": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "fileName": {
            "type": "string"
          },
          "fileContent": {
            "type": "string"
          }
        },
        "required": [
          "fileName",
          "fileContent"
        ]
      }
    }
  },
  "required": [
    "requestID",
    "documents"
  ]
}

关键改动说明

  • 顶层type从array改为object:因为你的JSON根结构现在是包含两个成员的对象,不再是单纯的文档数组
  • 添加requestID属性:定义为字符串类型,并且加入required数组确保它必须存在
  • 新增documents数组属性:把你原来的文档数组Schema移到这个属性里,保持每个文档对象的校验规则不变
  • 顶层required数组:明确指定requestID和documents都是必填字段

对应的示例JSON数据结构如下:

{
  "requestID": "req-123456",
  "documents": [
    {
      "fileName": "doc1.txt",
      "fileContent": "这是文档1的内容"
    },
    {
      "fileName": "doc2.pdf",
      "fileContent": "base64编码的PDF内容"
    }
  ]
}

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 10:41:18