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

如何在JOLT Spec中添加双AND条件实现地址映射过滤

问题

需要将输入JSON中的LandingDetails.AddressDetails.UnformattedAddress映射到输出的ApcantDetails.Address,要求仅当UnformattedAddressIn="Y" 且 PostalAddressTypeCd="001"时执行映射。目前已实现单条件过滤UnformattedAddressIn="Y",需补充多条件判断。

输入请求JSON

{"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 Spec

[{"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}}

解决方案

要实现两个条件的与逻辑,只需在AddressDetails的数组遍历层级下,先通过PostalAddressTypeCd的"001"做第一层过滤,再嵌套原有的UnformattedAddressIn="Y"的判断逻辑,同时调整&索引(因为层级增加了一层,索引值需要对应调整)。

修改后的JOLT Spec如下:

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

逻辑说明

  1. 先在AddressDetails的每个元素下,判断PostalAddressTypeCd是否为"001",只有符合的才进入后续逻辑;
  2. 在"001"的分支下,再判断UnformattedAddressIn是否为"Y",双重过滤后才执行地址映射;
  3. 调整@(层级)和[&索引]的数值:因为新增了PostalAddressTypeCd这一层级,所以原有向上引用的层级数需要加1,数组索引也需要对应调整(例如原@(2,PostCd)变为@(3,PostCd),原[&5]变为[&6])。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.19 15:28:12