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

基于指定条件规则的Jolt数组元素映射实现需求

Jolt数组元素条件映射实现

输入示例(Input.json)

{
  "accountType": "ADMIN",
  "id": "aaab-ccc-ddd-eeeAAA",
  "relationship": "DIRECT",
  "accountInfo": {
    "partyTypeCode": "PARTNER",
    "source": "Facebook",
    "internalAccount": true,
    "category": "Father"
  },
  "accountAddress": [
    {
      "addressId": "0016u00000bsqfrAddId",
      "integrationId": "0016u00000bsqfrInt",
      "addressType": "office",
      "shipToAddress": "Y",
      "soldToAddress": "N"
    },
    {
      "addressId": "12316u00000bsqfrAddId",
      "integrationId": "12316u00000bsqfrInt",
      "addressType": "home",
      "shipToAddress": "N",
      "soldToAddress": "Y"
    }
  ]
}

输出示例(Output.json)

{
  "PostalAddress": {
    "item": [
      {
        "key": {
          "primaryKey": "0016u00000bsqfrAddId~HDADDRESS~Admin"
        },
        "PrimaryAddress": {
          "addrTyp": "Y",
          "addrDes": "PRIMARY"
        },
        "SecondaryAddress": {
          "addrTyp": "N",
          "addrDes": "OPTIONAL"
        }
      }
    ]
  }
}

映射规则

  • 当source为"Facebook"时,primaryKey值为addressId+"~HDADDRESS~"+驼峰格式的accountType
  • 当source为"Google"时,primaryKey值为integrationId+驼峰格式的accountType
  • 将输入的shipToAddress直接映射为PrimaryAddress.addrTyp,addrDes固定为"PRIMARY"
  • 将输入的soldToAddress直接映射为SecondaryAddress.addrTyp,addrDes固定为"OPTIONAL"

Jolt转换规范

[
  {
    "operation": "shift",
    "spec": {
      "accountAddress": {
        "*": {
          "shipToAddress": "PostalAddress.item[&1].PrimaryAddress.addrTyp",
          "soldToAddress": "PostalAddress.item[&1].SecondaryAddress.addrTyp",
          "#PRIMARY": "PostalAddress.item[&1].PrimaryAddress.addrDes",
          "#OPTIONAL": "PostalAddress.item[&1].SecondaryAddress.addrDes",
          "@(2,accountInfo.source)": {
            "Facebook": {
              "@(2,addressId)": "PostalAddress.item[&3].key.primaryKey",
              "@(3,accountType)": {
                "ADMIN": "#~HDADDRESS~Admin",
                "*": "#~HDADDRESS~&"
              }
            },
            "Google": {
              "@(2,integrationId)": "PostalAddress.item[&3].key.primaryKey",
              "@(3,accountType)": {
                "ADMIN": "#Admin",
                "*": "#&"
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "PostalAddress": {
        "item": {
          "*": {
            "key": {
              "primaryKey": "=concat(@(1,primaryKey[0]),@(1,primaryKey[1]))"
            }
          }
        }
      }
    }
  }
]

转换说明

  1. Shift操作:遍历accountAddress数组元素,完成基础字段映射;同时根据accountInfo.source的取值,分别选取addressId或integrationId,并对accountType做驼峰格式转换(示例中已处理ADMIN转Admin,可扩展其他类型)。
  2. Modify操作:通过concat函数将拆分存储的primaryKey片段拼接为完整字符串,得到最终的主键值。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 07:24:58