元素数组的 Jolt 条件映射

问题描述 投票:0回答:1

输入.json

{
  "accountType": "ADMIN",
  "id": "aaab-ccc-ddd-eeeAAA",
  "relationship": "DIRECT",
  "accountInfo": {
    "partyTypeCode": "PARTNER",
    "source": "Facebbok",
    "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"
    }
  ]
}

输出.json

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

上述输出的标准

  1. 当来源是“Facebook”时,主键值应该是addressId+“~HDADDRESS”+accountType(应该是camelcase)
  2. 当来源为“Google”时,主键值应为integrationId+accountType(应为驼峰式)
  3. 将输入参数的shipToAddress原样映射到PrimaryAddress.addrTyp,并将addrDes的值硬编码为“PRIMARY”
  4. 将输入参数的oldToAddress按原样映射到SecondaryAddress.addrTyp,并将addrDes的值硬编码为“OPTIONAL”
transform transformation jolt
1个回答
0
投票
    [
        { //transfrom to lowercase
            "operation": "modify-overwrite-beta",
            "spec": {
            "accountType": "=toLower"
            }
        },
        { //split all the characters
            "operation": "modify-overwrite-beta",
            "spec": {
            "accountType": "=split('',@(1,&))"
            }
        },
        { //convert 1st character to uppercase
            "operation": "modify-overwrite-beta",
            "spec": {
            "accountType": {
                "[0]": "=toUpper"
            }
            }
        },
        { //convert array back to string
            "operation": "modify-overwrite-beta",
            "spec": {
            "accountType": "=join('',@(1,&))"
            }
        }, { //concat ids
            "operation": "modify-overwrite-beta",
            "spec": {
            "accountAddress": {
                "*": {
                "Fprim": "=concat(@(1,addressId),'~HDADDRESS~',@(3,accountType))",
                "Gprim": "=concat(@(1,integrationId),@(3,accountType))"
                }
            }
            }
        },
        {
            "operation": "shift",
            "spec": {
            "accountInfo": {
                "source": {
                "Facebook": { //if source is Facebook
                    "@4,accountAddress": {
                    "*": {
                        "Fprim": "PostalAdress.items[&1].key.primaryKey"
                    }
                    }
                },
                "Google": { //if source is Google
                    "@4,accountAddress": {
                    "*": {
                        "Gprim": "PostalAdress.items[&1].key.primaryKey"
                    }
                    }
                }
                }
            },
            "accountAddress": {
                "*": {
                "shipToAddress": "PostalAdress.items[&1].PrimaryAddress.addrTyp",
                "#PRIMARY": "PostalAdress.items[&1].PrimaryAddress.addrDes",
                "soldToAddress": "PostalAdress.items[&1].SecondaryAddress.addrTyp",
                "#OPTIONAL": "PostalAdress.items[&1].SecondaryAddress.addrDes"
                }
            }
            }
        }
    ]
© www.soinside.com 2019 - 2024. All rights reserved.