JOLT 规格包括两个 AND 条件

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

我有一个输入请求 -

{
  "ReqDet": {
    "RequestNo": "9274613",
    "AppliCd": "003",
     "SortCd" : 12
  },
  "AppDetails": {
      "ProductId" : 1234
  },
  "LandingDetails": [
    {
      "PId": 12345,
      "PartyIdentifiers": [
        {
          "ExtSysId": 4,
          "ExtPartyIdTx": "12345"
        }
      ],
      "AddressDetails": [
        {
          "PostalAddressTypeCd": "003",
          "PostCd": "TN1 1SS",
          "AddressResidenceDr": {
            "YearsDr": 4,
            "MonthsDr": 8
          },
          "FormattedAddressIn": "N",
          "FormattedAddress": {
            "SubBuildingNm": "125",
            "BuildingNm": "GANM",
            "BuildingNo": "12",
            "AddressLine1Tx": "Grove Hill Garden",
            "AddressDistrictNm": "Tunbridge Wells",
            "AddressTownNm": "Kent",
            "AddressCountyNm": ""
          },
          "UnformattedAddressIn": "Y",
          "UnformattedAddress": {
            "UnstrdPostalAddrssTypeCd": "001",
            "AddressLine1Tx": "11600 Hidden Grove Trail",
            "AddressLine2Tx": "Charlotte",
            "AddressLine3Tx": "North Carolina",
            "AddressLine4Tx": ""
          }
        },
        {
          "PostalAddressTypeCd": "001",
          "AddressResidenceDr": {
            "YearsDr": 4,
            "MonthsDr": 8
          },
          "PostCd": "TN1 1SS",
          "FormattedAddressIn": "N",
          "FormattedAddress": {
            "SubBuildingNm": "125",
            "BuildingNm": "GANM",
            "BuildingNo": "12",
            "AddressLine1Tx": "Jamming Garden",
            "AddressDistrictNm": "Tunbridge Wells",
            "AddressTownNm": "Kent",
            "AddressCountyNm": ""
          },
          "UnformattedAddressIn": "Y",
          "UnformattedAddress": {
            "UnstrdPostalAddrssTypeCd": "001",
            "AddressLine1Tx": "11600 Hidden Grove Trail",
            "AddressLine2Tx": "Charlotte",
            "AddressLine3Tx": "North Carolina",
            "AddressLine4Tx": ""
          }
        }
      ]
    },
    {
      "PId": 12345,
      "PartyIdentifiers": [
        {
          "ExtSysId": 4,
          "ExtPartyIdTx": "12345"
        }
      ],
      "AddressDetails": [
        {
          "PostalAddressTypeCd": "001",
          "PostCd": "TN1 1SS",
          "AddressResidenceDr": {
            "YearsDr": 4,
            "MonthsDr": 8
          },
          "FormattedAddressIn": "Y",
          "FormattedAddress": {
            "SubBuildingNm": "125",
            "BuildingNm": "GANM",
            "BuildingNo": "12",
            "AddressLine1Tx": "Grove Hill Garden",
            "AddressDistrictNm": "Tunbridge Wells",
            "AddressTownNm": "Kent",
            "AddressCountyNm": ""
          },
          "UnformattedAddressIn": "Y",
          "UnformattedAddress": {
            "UnstrdPostalAddrssTypeCd": "001",
            "AddressLine1Tx": "11600 Hidden Grove Trail",
            "AddressLine2Tx": "Charlotte",
            "AddressLine3Tx": "North Carolina",
            "AddressLine4Tx": ""
          }
        },
        {
          "PostalAddressTypeCd": "001",
          "AddressResidenceDr": {
            "YearsDr": 4,
            "MonthsDr": 8
          },
          "PostCd": "TN1 1SS",
          "FormattedAddressIn": "N",
          "FormattedAddress": {
            "SubBuildingNm": "125",
            "BuildingNm": "GANM",
            "BuildingNo": "12",
            "AddressLine1Tx": "Jamming Garden",
            "AddressDistrictNm": "Tunbridge Wells",
            "AddressTownNm": "Kent",
            "AddressCountyNm": ""
          },
          "UnformattedAddressIn": "Y",
          "UnformattedAddress": {
            "UnstrdPostalAddrssTypeCd": "001",
            "AddressLine1Tx": "11600 Hidden Grove Trail",
            "AddressLine2Tx": "Charlotte",
            "AddressLine3Tx": "North Carolina",
            "AddressLine4Tx": ""
          }
        }
      ]
    }
  ]
}

这是我的 JOLT 规格 -

[
  {
    "operation": "shift",
    "spec": {
      "AppDetails": {
        "ProductId": "AppDetails.ProductId"
      },
      "ReqDet": {
        "SortCd": "AppDetails.SortCd"
      },
      "LandingDetails": {
        "*": {
          "PId": "ApcantDetails.[&1].PId",
          "PartyIdentifiers": "ApcantDetails.[&1].PartyIdentifiers",
          "AddressDetails": {
            "*": {
              "UnformattedAddressIn": {
                "Y": {
                  "@(2,PostCd)": "ApcantDetails.[&5].Address.[&3].PostalCode",
                  "@(2,UnformattedAddress)": {
                    "AddressLine1Tx": "ApcantDetails.[&6].Address.[&4].Address1",
                    "AddressLine2Tx": "ApcantDetails.[&6].Address.[&4].Address2",
                    "AddressLine3Tx": "ApcantDetails.[&6].Address.[&4].Address3",
                    "AddressLine4Tx": "ApcantDetails.[&6].Address.[&4].Address4"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
]

预期输出 json -

{
    "ApcantDetails": [
        {
            "PId": 1230465,
            "ApplicantNumber": 1,
            "PartyIdentifiers": [
                {
                    "ExtSysId": 2,
                    "ExtPartyIdTx": "+30584"
                },
                {
                    "ExtSysId": 4,
                    "ExtPartyIdTx": "56789"
                }
            ],
            "Address": [
                {
                    "PostalCode": "TN1 1SS",
                    "Address1": "25 Ssdf",
                    "Address2": "Fsdf",
                    "Address3": "",
                    "Address4": ""
                },
                {
                    "PostalCode": "HX1 2RG",
                    "Address1": "Trinity Road",
                    "Address2": "Halifax",
                    "Address3": "West Yorkshire",
                    "Address4": "United Kingdom"
                }
            ]
        },
        {
            "PId": 126541,
            "ApplicantNumber": 2,
            "PartyIdentifiers": [
                {
                    "ExtSysId": 2,
                    "ExtPartyIdTx": "+30584"
                },
                {
                    "ExtSysId": 4,
                    "ExtPartyIdTx": "56789"
                }
            ],
            "Address": [
                {
                    "PostalCode": "TN1 1SS",
                    "Address1": "25 Ssdf",
                    "Address2": "Fsdf",
                    "Address3": "",
                    "Address4": ""
                },
                {
                    "PostalCode": "HX1 2RG",
                    "Address1": "Trinity Road",
                    "Address2": "Halifax",
                    "Address3": "West Yorkshire",
                    "Address4": "United Kingdom"
                }
            ]
        }
    ],
    "AppDetails": {
        "ProductId": 731,
    }
}

所以在这里我尝试将 LandingDetails.AddressDetails.UnformattedAddress 映射到 ApcantDetails.Address 。现在,仅当 UnformattedAddressIn = "Y" AND PostalAddressTypeCd="001" 时才会发生映射。我可以添加对 UnformattedAddressIn 的检查,但如何添加这两项检查?

json transformation jolt
1个回答
0
投票

您可以使用 UnformattedAdressIn 添加另一个条件,如下所示。

[
{
"operation": "shift",
"spec": {
  "AppDetails": {
    "ProductId": "AppDetails.ProductId"
  },
  "ReqDet": {
    "SortCd": "AppDetails.SortCd"
  },
  "LandingDetails": {
    "*": {
      "PId": "ApcantDetails.[&1].PId",
      "PartyIdentifiers": "ApcantDetails.[&1].PartyIdentifiers",
      "AddressDetails": {
        "*": {
          "UnformattedAddressIn": {
            "Y": {
              "@(2,PostalAddressTypeCd)": {
                "001": {
                  "@(4,PostCd)": "ApcantDetails.[&7].Address.[&5].PostalCode",
                  "@(4,UnformattedAddress)": {
                    "AddressLine1Tx": "ApcantDetails.[&8].Address.[&6].Address1",
                    "AddressLine2Tx": "ApcantDetails.[&8].Address.[&6].Address2",
                    "AddressLine3Tx": "ApcantDetails.[&8].Address.[&6].Address3",
                    "AddressLine4Tx": "ApcantDetails.[&8].Address.[&6].Address4"
                  }
                }
              }
            }
          }
        }
      }
    }
  }
}
}
]
© www.soinside.com 2019 - 2024. All rights reserved.