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

编写Dynamic Jolt规格处理外层数组第2元素含嵌套数组场景

Jolt规格修正:适配含嵌套identifiers数组的routeSegments

输入JSON

{
  "routeSegments": [
    {
      "id": "seg1",
      "name": "Segment 1"
    },
    {
      "id": "seg2",
      "name": "Segment 2",
      "identifiers": [
        {
          "type": "CODE",
          "value": "ABC123"
        },
        {
          "type": "ID",
          "value": "X789"
        }
      ]
    }
  ]
}

预期输出JSON

{
  "routes": [
    {
      "segmentId": "seg1",
      "segmentName": "Segment 1"
    },
    {
      "segmentId": "seg2",
      "segmentName": "Segment 2",
      "codes": [
        {
          "codeType": "CODE",
          "codeValue": "ABC123"
        },
        {
          "codeType": "ID",
          "codeValue": "X789"
        }
      ]
    }
  ]
}

原尝试的Jolt规格

[
  {
    "operation": "shift",
    "spec": {
      "routeSegments": {
        "*": {
          "id": "routes[&1].segmentId",
          "name": "routes[&1].segmentName"
        }
      }
    }
  }
]

修正后的Jolt规格

[
  {
    "operation": "shift",
    "spec": {
      "routeSegments": {
        "*": {
          "id": "routes[&1].segmentId",
          "name": "routes[&1].segmentName",
          "identifiers": {
            "*": {
              "type": "routes[&3].codes[&1].codeType",
              "value": "routes[&3].codes[&1].codeValue"
            }
          }
        }
      }
    }
  }
]

修正说明

  • 用&3对应外层routeSegments的数组下标,确保每个identifiers里的元素能精准映射到所属的routes条目下的codes数组
  • 保留原有的基础字段映射逻辑,补上嵌套数组的处理规则,解决部分元素包含identifiers嵌套数组时的转换异常问题

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.15 10:12:50