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

如何使用Jolt将多字符串列表的同索引元素组合为目标对象

Jolt 转换实现方案

实现该需求的完整Jolt转换规则如下:

[
  {
    "operation": "shift",
    "spec": {
      "recordSet": {
        "*": {
          "id": "historyDetails[&1].historyId",
          "bucketIdArray": {
            "*": {
              "@": "historyDetails[&3].bucketlist[&1].bucketId"
            }
          },
          "bucketNameArray": {
            "*": {
              "@": "historyDetails[&3].bucketlist[&1].bucketName"
            }
          },
          "bucketUsageArray": {
            "*": {
              "@": "historyDetails[&3].bucketlist[&1].bucketUsage"
            }
          },
          "postBucketValueArray": {
            "*": {
              "@": "historyDetails[&3].bucketlist[&1].postBucketValue"
            }
          }
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "historyDetails": "datas.historyDetails"
    }
  }
]

规则说明

  • 第一层shift操作遍历recordSet数组的每一条记录,先将原记录的id字段映射为historyDetails对应下标的historyId字段
  • 对每条记录下的四个数组分别遍历,利用通配符匹配数组下标,将同一下标的数组元素映射到bucketlist相同下标的对象对应属性中,其中&3表示向上回溯3层取recordSet的数组下标,&1表示取当前数组的下标,保证字段对应关系准确
  • 第二层shift操作将生成的historyDetails数组嵌套到datas节点下,匹配预期输出的结构

注意事项

你提供的预期结果存在两处笔误:id为123的记录对应的第二个bucket对象中,bucketName应为输入中的EmployeeBucket100、bucketUsage应为输入中的5000,上述转换规则会严格按照输入的字段值进行映射。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.27 14:54:03