首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >通过使用using动态匹配值来合并两个数组

通过使用using动态匹配值来合并两个数组
EN

Stack Overflow用户
提问于 2022-10-12 22:29:41
回答 1查看 32关注 0票数 0

我是新来的震动和有困难的时间获得预期的产出

输入JSON

代码语言:javascript
复制
[
  {
    "getPatientDemographicDetailsOutput": [
      {
        "Message": "SUCCESS",
        "Results": [
          [
            {
              "APS_Age__c": "7 Years",
              "Id": "1234",
              "LastName": "LName0915-6",
              "APS_DOB__c": "2014-11-25",
              "Contacts__r": {
                "totalSize": 2,
                "records": [
                  {
                    "Alternate_Phone_1__c": "1458296321",
                    "Alternate_Phone_2__c": "(732) 318-3232",
                    "Correspondence_City__c": "Charlotte",
                    "Email_Address__c": "sohel@abc.com",
                    "Correspondence_State__c": "NC",
                    "State__c": "NC",
                    "Patient__c": "1234",
                    "Correspondence_Time_Zone__c": "EST",
                    "Correspondence_ZipCode_Name__c": "28222",
                    "Primary__c": true,
                    "Primary_Phone__c": "Mobile",
                    "Correspondence_Country__c": "USA",
                    "Country__c": "USA",
                    "Address_Line_2__c": "City",
                    "City__c": "Charlotte",
                    "Type__c": "Self",
                    "Zip_Code_Name__c": "28222",
                    "Address_Line_1__c": "Bangalore",
                    "Id": "11111",
                    "Correspond_Address_Line_1__c": "Bangalore",
                    "Correspond_Address_Line_2__c": "City",
                    "Mobile_Phone_for_Campaigns__c": "+1(732) 318-1232"
                  },
                  {
                    "Correspondence_City__c": "INTERNAL REVENUE SERVICE",
                    "Correspondence_State__c": "NY",
                    "Type__c": "Caregiver",
                    "Patient__c": "1234",
                    "Id": "22222",
                    "Correspond_Address_Line_1__c": "test address",
                    "Correspondence_Time_Zone__c": "EST",
                    "Correspondence_ZipCode_Name__c": "00501",
                    "Primary__c": false,
                    "Correspondence_Country__c": "USA"
                  }
                ],
                "done": true
              }
            }
          ],
          [
            {
              "Contact__c": "11111",
              "Text_Consent_Date__c": "2019-11-23",
              "Text_Messaging__c": "Yes",
              "Id": "54545454"
            }
          ]
        ]
      }
    ]
  }
]

预期产出

代码语言:javascript
复制
[
    {
        "APS_Age__c": "7 Years",
        "Id": "1234",
        "LastName": "LName0915-6",
        "APS_DOB__c": "2014-11-25",
        "Alternate_Phone_1__c": "1458296321",
        "Alternate_Phone_2__c": "(732) 318-3232",
        "Correspondence_City__c": "Charlotte",
        "Correspond_Address_Line_1__c": "Bangalore",
        "Correspond_Address_Line_2__c": "City",
        "Mobile_Phone_for_Campaigns__c": "+1(732) 318-1232",
        "Primary__c": true,
        "Text_Consent_Date__c": "2019-11-23",
        "Text_Messaging__c": "Yes"
    }
]

转换后两个字段的逻辑-- Text_Consent_Date__c和Text_Messaging__c

  • 输入JSON中的“结果”中有两个数组。我希望从第二个数组中选择Text_Consent_Date__c和Text_Messaging__c,如果Primary__c =true(仅从主联系人列表中选择主联系人)和Id (来自Contacts__r)与Contact__c(第二个json数组中的字段)

匹配

EN

回答 1

Stack Overflow用户

发布于 2022-10-13 05:56:32

此shift操作将帮助您生成所需的json:

代码语言:javascript
复制
 [
  {
    "operation": "shift",
    "spec": {
      "*": {
        "getPatientDemographicDetailsOutput": {
          "*": {
            "Results": {
              "*": {
                "*": {
                  "*": "[&2].&",
                  "Contacts__r": {
                    "records": {
                      "*": {
                        "Alternate_Phone_1__c": "[&1].&",
                        "Alternate_Phone_2__c": "[&1].&",
                        "Correspondence_City__c": "[&1].&",
                        "Correspond_Address_Line_1__c": "[&1].&",
                        "Correspond_Address_Line_2__c": "[&1].&",
                        "Mobile_Phone_for_Campaigns__c": "[&1].&",
                        "Primary__c": "[&1].&"
                      }
                    }
                  },
                  "Text_Consent_Date__c": "[&1].&",
                  "Text_Messaging__c": "[&1].&"
                }
              }
            }
          }
        }
      }
    }
  }
]
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74048600

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档