基于指定条件规则的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]))" } } } } } } ]
转换说明
- Shift操作:遍历
accountAddress数组元素,完成基础字段映射;同时根据accountInfo.source的取值,分别选取addressId或integrationId,并对accountType做驼峰格式转换(示例中已处理ADMIN转Admin,可扩展其他类型)。 - Modify操作:通过
concat函数将拆分存储的primaryKey片段拼接为完整字符串,得到最终的主键值。
内容的提问来源于stack exchange,提问作者Rakesh GR
相关产品推荐
相关产品推荐

