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

JOLT映射值与ID循环处理:合并同ID的OrgUnits数组

JOLT转换解决方案:合并同ID的OrgUnits并完成字段映射

输入示例

[
  {
    "id": "ACC-001",
    "name": "销售费用账户",
    "LVL2": "OU-001"
  },
  {
    "id": "ACC-001",
    "name": "销售费用账户",
    "LVL2": "OU-002"
  },
  {
    "id": "ACC-002",
    "name": "管理费用账户",
    "LVL2": "OU-003"
  }
]

目标输出示例

[
  {
    "glAccountName": "销售费用账户",
    "glAccountDescription": "销售费用账户",
    "referenceCodeForEntity": "ACC-001",
    "integrationTrackingNumber": "ACC-001",
    "fixedField1": "固定值1",
    "fixedField2": "固定值2",
    "OrgUnits": ["OU-001", "OU-002"]
  },
  {
    "glAccountName": "管理费用账户",
    "glAccountDescription": "管理费用账户",
    "referenceCodeForEntity": "ACC-002",
    "integrationTrackingNumber": "ACC-002",
    "fixedField1": "固定值1",
    "fixedField2": "固定值2",
    "OrgUnits": ["OU-003"]
  }
]

最终JOLT Spec

[
  {
    "operation": "shift",
    "spec": {
      "*": {
        "id": "@(1,id).id",
        "name": "@(1,id).name",
        "LVL2": "@(1,id).OrgUnits[]"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "id": "[&1].referenceCodeForEntity",
        "id": "[&1].integrationTrackingNumber",
        "name": "[&1].glAccountName",
        "name": "[&1].glAccountDescription",
        "OrgUnits": "[&1].OrgUnits",
        "#固定值1": "[&1].fixedField1",
        "#固定值2": "[&1].fixedField2"
      }
    }
  }
]

步骤说明

  • 第一步(聚合同ID条目):通过shift操作,以每个条目的id作为分组键,将相同id的LVL2值收集到OrgUnits数组中,同时保留id和name字段,避免生成独立对象。
  • 第二步(字段映射与固定值添加):再次使用shift将聚合后的对象转换为数组结构,完成字段映射:
    • 原id同时映射到referenceCodeForEntity和integrationTrackingNumber
    • 原name同时映射到glAccountName和glAccountDescription
    • 用#前缀添加固定字段的静态值
    • 直接保留聚合好的OrgUnits数组

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 23:35:07