Search code examples
arraysjsonjolt

Jolt spec to perform the grouping and remove the duplicate from nested json


Please help me in providing jolt spec or update the below tried jolt spec to get desired output json shown below I already posted the similar question but tried to solution but not able to remove the duplicate entry inside the WFI_Customer and WFI_Reasons arrays, please help in fixing the issue thanks in advance .

input json

[
  {
    "ALERT_IDENTIFIER": "123",
    "FIRST_REASON": "CB05b High amount credit transactions compared to credit history",
    "ALERT_TEXT": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "ALERT_SCORE": 27,
    "EVENT_DATE": 1615660200000,
    "CUSTOMER_ID": "CUST12",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1045,
    "WW_ORGUNIT_CODE": "SE_EMP",
    "CREATION_TIMESTAMP": 1615902235602,
    "REASON_SRC_UNIQUE_ID": "TEST123456",
    "REASON_NAME": "CB05b High amount credit transactions compared to credit history",
    "REASON_SCORE": 27,
    "REASON_TIME_PERIOD": "Daily",
    "REASON_DESCRIPTION": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "DATASOURCE_RECORD_ID": null,
    "DATASOURCE_ACC_ID": "NOCTEST1234",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1615660200000,
    "LINKED_ENTITY_NAME": "Test2",
    "LINKED_ENTITY_KEY": "2"
  },
  {
    "ALERT_IDENTIFIER": "123",
    "FIRST_REASON": "CB05b High amount credit transactions compared to credit history",
    "ALERT_TEXT": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "ALERT_SCORE": 27,
    "EVENT_DATE": 1615660200000,
    "CUSTOMER_ID": "CUST12",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1045,
    "WW_ORGUNIT_CODE": "SE_EMP",
    "CREATION_TIMESTAMP": 1615902235602,
    "REASON_SRC_UNIQUE_ID": "TEST123456",
    "REASON_NAME": "CB05b High amount credit transactions compared to credit history",
    "REASON_SCORE": 27,
    "REASON_TIME_PERIOD": "Daily",
    "REASON_DESCRIPTION": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "DATASOURCE_RECORD_ID": null,
    "DATASOURCE_ACC_ID": "NOCTEST1234",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1615660200000,
    "LINKED_ENTITY_NAME": null,
    "LINKED_ENTITY_KEY": null
  },
  {
    "ALERT_IDENTIFIER": "123",
    "FIRST_REASON": "CB05b High amount credit transactions compared to credit history",
    "ALERT_TEXT": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "ALERT_SCORE": 27,
    "EVENT_DATE": 1615660200000,
    "CUSTOMER_ID": "CUST12",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1045,
    "WW_ORGUNIT_CODE": "SE_EMP",
    "CREATION_TIMESTAMP": 1615902235602,
    "REASON_SRC_UNIQUE_ID": "TEST123456",
    "REASON_NAME": "CB05b High amount credit transactions compared to credit history",
    "REASON_SCORE": 27,
    "REASON_TIME_PERIOD": "Daily",
    "REASON_DESCRIPTION": "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change – value",
    "DATASOURCE_RECORD_ID": null,
    "DATASOURCE_ACC_ID": "NOCTEST1234",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1615660200000,
    "LINKED_ENTITY_NAME": "Test1",
    "LINKED_ENTITY_KEY": "1"
  },
  {
    "ALERT_IDENTIFIER": "345",
    "FIRST_REASON": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "ALERT_TEXT": "CB03b: In the previous week a transaction was made to or from Philippines [PH] totalling 13000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "ALERT_SCORE": 368.4,
    "EVENT_DATE": 1935253800000,
    "CUSTOMER_ID": "CUST123",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1005,
    "WW_ORGUNIT_CODE": "NO",
    "CREATION_TIMESTAMP": 1616030994216,
    "REASON_SRC_UNIQUE_ID": "NOCTEST1234",
    "REASON_NAME": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "REASON_SCORE": 91.4,
    "REASON_TIME_PERIOD": "ForEachRecord",
    "REASON_DESCRIPTION": "CB03b: In the previous week a transaction was made to or from Chad [TD] totalling 10000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "DATASOURCE_RECORD_ID": "Mar07UNIQUEECB03BNO93PS",
    "DATASOURCE_ACC_ID": "NOCTEST123",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1935253800000,
    "LINKED_ENTITY_NAME": null,
    "LINKED_ENTITY_KEY": null
  },
  {
    "ALERT_IDENTIFIER": "345",
    "FIRST_REASON": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "ALERT_TEXT": "CB03b: In the previous week a transaction was made to or from Philippines [PH] totalling 13000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "ALERT_SCORE": 368.4,
    "EVENT_DATE": 1935253800000,
    "CUSTOMER_ID": "CUST123",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1005,
    "WW_ORGUNIT_CODE": "NO",
    "CREATION_TIMESTAMP": 1616030994216,
    "REASON_SRC_UNIQUE_ID": "NOCTEST1234",
    "REASON_NAME": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "REASON_SCORE": 91.9,
    "REASON_TIME_PERIOD": "ForEachRecord",
    "REASON_DESCRIPTION": "CB03b: In the previous week a transaction was made to or from Russia [RU] totalling 11000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "DATASOURCE_RECORD_ID": "TEST",
    "DATASOURCE_ACC_ID": "NOCTEST123",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1935253800000,
    "LINKED_ENTITY_NAME": null,
    "LINKED_ENTITY_KEY": null
  },
  {
    "ALERT_IDENTIFIER": "345",
    "FIRST_REASON": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "ALERT_TEXT": "CB03b: In the previous week a transaction was made to or from Philippines [PH] totalling 13000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "ALERT_SCORE": 368.4,
    "EVENT_DATE": 1935253800000,
    "CUSTOMER_ID": "CUST123",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1005,
    "WW_ORGUNIT_CODE": "NO",
    "CREATION_TIMESTAMP": 1616030994216,
    "REASON_SRC_UNIQUE_ID": "NOCTEST1234",
    "REASON_NAME": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "REASON_SCORE": 91.9,
    "REASON_TIME_PERIOD": "ForEachRecord",
    "REASON_DESCRIPTION": "CB03b: In the previous week a transaction was made to or from Russia [RU] totalling 11000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "DATASOURCE_RECORD_ID": "TEST",
    "DATASOURCE_ACC_ID": "NOCTEST123",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1935253800000,
    "LINKED_ENTITY_NAME": null,
    "LINKED_ENTITY_KEY": null
  },
  {
    "ALERT_IDENTIFIER": "345",
    "FIRST_REASON": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "ALERT_TEXT": "CB03b: In the previous week a transaction was made to or from Philippines [PH] totalling 13000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "ALERT_SCORE": 368.4,
    "EVENT_DATE": 1935253800000,
    "CUSTOMER_ID": "CUST123",
    "CUSTOMER_SEGMENT": "SILVER",
    "CUSTOMER_TYPE_CODE": "P",
    "QUEUE_FASTTRACK_FLAG": "0",
    "CHECK_NAME": null,
    "ACCOUNT_ID": "-1",
    "TRANSACTION_ID": null,
    "WW_ORGUNIT_ID": 1005,
    "WW_ORGUNIT_CODE": "NO",
    "CREATION_TIMESTAMP": 1616030994216,
    "REASON_SRC_UNIQUE_ID": "NOCTEST1234",
    "REASON_NAME": "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
    "REASON_SCORE": 91.9,
    "REASON_TIME_PERIOD": "ForEachRecord",
    "REASON_DESCRIPTION": "CB03b: In the previous week a transaction was made to or from Russia [RU] totalling 11000.00 EUR. <br/><br/>This is a new country compared to the customer’s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
    "DATASOURCE_RECORD_ID": "TEST",
    "DATASOURCE_ACC_ID": "NOCTEST123",
    "RISK_LEVEL": "Low",
    "EVENT_TIMESTAMP": 1935253800000,
    "LINKED_ENTITY_NAME": null,
    "LINKED_ENTITY_KEY": null
  }
]

Expected output json without any duplicate like below

[ {
  "WF_Workitem" : {
    "GlobalID" : "AMALERT123",
    "InvLifecycleStatus" : null,
    "SourceSystem" : "AM",
    "WF_Instance" : {
      "Description" : "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change ? value",
      "EventDate" : 1615660200000,
      "External_Data_Reference" : [ {
        "ApplicationId" : "null",
        "External_Data_Reference_Type_Dict" : [ {
          "Description" : "Account Type - ID stored is the Account_ID",
          "Name" : "Account_ID",
          "ReferenceTypeId" : "1"
        } ],
        "InstanceID" : "123",
        "ReferenceID" : "-1",
        "ReferenceTypeId" : "1"
      }, {
        "ApplicationId" : "null",
        "External_Data_Reference_Type_Dict" : [ {
          "Description" : "Transaction Type - ID stored is the Transaction_ID",
          "Name" : "Transaction_ID",
          "ReferenceTypeId" : "2"
        } ],
        "InstanceID" : "123",
        "ReferenceID" : null,
        "ReferenceTypeId" : "2"
      } ],
      "FastTrack" : "NO",
      "FirstReasonName" : "CB05b High amount credit transactions compared to credit history",
      "InstanceID" : "123",
      "OrgUnitCode" : "SE_EMP",
      "OrgUnitID" : 1045,
      "Score" : 27,
      "SubScenarioName" : null,
      "WFI_Customer" : [ {
        "CustomerID" : "CUST12",
        "CustomerSegment" : "SILVER",
        "CustomerTypeCode" : "NATURAL PERSON"
      } ],
      "WFI_Reasons" : [ {
        "CustomerRiskLevel" : "LOW",
        "DetectionScore" : 27,
        "DetectionTimeStamp" : 1615660200000,
        "ReasonDescription" : "CB05b: In the previous day there was a high amount of incoming transactions totalling 3000.00 EUR. This is deviating from historic behaviour. <br/>Risk indicators: <br/>- Behavioural change ? value",
        "ReasonTimePeriod" : "Daily",
        "SRC_AccountID" : "NOCTEST1234",
        "SRC_ID" : "TEST123456",
        "SRC_TransactionID" : null,
        "ScenarioName" : "CB05b High amount credit transactions compared to credit history"
      } ],
      "WFinstanceType" : "ALERT"
    },
    "WF_Linked_References" : {
      "Global_ID" : null,
      "Local_ID" : null,
      "RelationshipType" : null,
      "SourceRef" : null
    },
    "WF_Workitem_Link" : [ {
      "LinkedEntityKey" : "2",
      "LinkedEntityName" : "Test2"
    }, {
      "LinkedEntityKey" : null,
      "LinkedEntityName" : null
    }, {
      "LinkedEntityKey" : "1",
      "LinkedEntityName" : "Test1"
    } ],
    "WFeventTimestamp" : 1615902235602,
    "opDomain" : "TM"
  }
}, {
  "WF_Workitem" : {
    "GlobalID" : "AMALERT345",
    "InvLifecycleStatus" : null,
    "SourceSystem" : "AM",
    "WF_Instance" : {
      "Description" : "CB03b: In the previous week a transaction was made to or from Philippines [PH] totalling 13000.00 EUR. <br/><br/>This is a new country compared to the customer?s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
      "EventDate" : 1935253800000,
      "External_Data_Reference" : [ {
        "ApplicationId" : "null",
        "External_Data_Reference_Type_Dict" : [ {
          "Description" : "Account Type - ID stored is the Account_ID",
          "Name" : "Account_ID",
          "ReferenceTypeId" : "1"
        } ],
        "InstanceID" : "345",
        "ReferenceID" : "-1",
        "ReferenceTypeId" : "1"
      }, {
        "ApplicationId" : "null",
        "External_Data_Reference_Type_Dict" : [ {
          "Description" : "Transaction Type - ID stored is the Transaction_ID",
          "Name" : "Transaction_ID",
          "ReferenceTypeId" : "2"
        } ],
        "InstanceID" : "345",
        "ReferenceID" : null,
        "ReferenceTypeId" : "2"
      } ],
      "FastTrack" : "NO",
      "FirstReasonName" : "CB03b Transaction with new terrorist country or a country with close proximity compared to history",
      "InstanceID" : "345",
      "OrgUnitCode" : "NO",
      "OrgUnitID" : 1005,
      "Score" : 368.4,
      "SubScenarioName" : null,
      "WFI_Customer" : [ {
        "CustomerID" : "CUST123",
        "CustomerSegment" : "SILVER",
        "CustomerTypeCode" : "NATURAL PERSON"
      } ],
      "WFI_Reasons" : [ {
        "CustomerRiskLevel" : "LOW",
        "DetectionScore" : 91.4,
        "DetectionTimeStamp" : 1935253800000,
        "ReasonDescription" : "CB03b: In the previous week a transaction was made to or from Chad [TD] totalling 10000.00 EUR. <br/><br/>This is a new country compared to the customer?s 180 days history, also considered a terrorist country or a country with close proximity to a terrorist country. <br/><br/>Risk indicators: <br/>- Behaviour Change - new country<br/>- Country Risk - Transactions with Terrorist Havens<br/>",
        "ReasonTimePeriod" : "ForEachRecord",
        "SRC_AccountID" : "NOCTEST123",
        "SRC_ID" : "NOCTEST1234",
        "SRC_TransactionID" : "Mar07UNIQUEECB03BNO93PS",
        "ScenarioName" : "CB03b Transaction with new terrorist country or a country with close proximity compared to history"
      } ],
      "WFinstanceType" : "ALERT"
    },
    "WF_Linked_References" : {
      "Global_ID" : null,
      "Local_ID" : null,
      "RelationshipType" : null,
      "SourceRef" : null
    },
    "WF_Workitem_Link" : [ {
      "LinkedEntityKey" : null,
      "LinkedEntityName" : null
    }, {
      "LinkedEntityKey" : null,
      "LinkedEntityName" : null
    }, {
      "LinkedEntityKey" : null,
      "LinkedEntityName" : null
    }, {
      "LinkedEntityKey" : null,
      "LinkedEntityName" : null
    } ],
    "WFeventTimestamp" : 1616030994216,
    "opDomain" : "TM"
  }
} ]

Spec tried but duplicate it is not removed could you please update the below jolt spec or provide new jolt spec to remove the duplicates

[
  {
    "operation": "modify-default-beta",
    "spec": {
      "*": {
        "comp_id": "=concat(@(1,ALERT_IDENTIFIER),'_', @(1,FIRST_REASON))"
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "@(1,comp_id).&[]"
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "CREATION_TIMESTAMP": "=firstElement(@(1,CREATION_TIMESTAMP))",
        "ALERT_IDENTIFIER": "=firstElement(@(1,ALERT_IDENTIFIER))",
        "FIRST_REASON": "=firstElement(@(1,FIRST_REASON))",
        "ALERT_TEXT": "=firstElement(@(1,ALERT_TEXT))",
        "ALERT_SCORE": "=firstElement(@(1,ALERT_SCORE))",
        "EVENT_DATE": "=firstElement(@(1,EVENT_DATE))",
        "WW_ORGUNIT_ID": "=firstElement(@(1,WW_ORGUNIT_ID))",
        "WW_ORGUNIT_CODE": "=firstElement(@(1,WW_ORGUNIT_CODE))",
        "WW_DOMAIN_CODE": "=firstElement(@(1,WW_DOMAIN_CODE))",
        "CHECK_NAME": "=firstElement(@(1,CHECK_NAME))",
        "ACCOUNT_ID": "=firstElement(@(1,ACCOUNT_ID))",
        "TRANSACTION_ID": "=firstElement(@(1,TRANSACTION_ID))",
        "QUEUE_FASTTRACK_FLAG": "=firstElement(@(1,QUEUE_FASTTRACK_FLAG))"
      }
    }
  },

  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[#2].&",
        "comp_id": null
      }
    }
  }
,
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[#2].&",
        "CREATION_TIMESTAMP": "[&1].WF_Workitem.WFeventTimestamp",
        "ALERT_IDENTIFIER": ["[&1].WF_Workitem.WF_Instance.InstanceID", "[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].InstanceID", "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].InstanceID"],
        "FIRST_REASON": "[&1].WF_Workitem.WF_Instance.FirstReasonName",
        "ALERT_TEXT": "[&1].WF_Workitem.WF_Instance.Description",
        "ALERT_SCORE": "[&1].WF_Workitem.WF_Instance.Score",
        "EVENT_DATE": "[&1].WF_Workitem.WF_Instance.EventDate",
        "WW_ORGUNIT_ID": "[&1].WF_Workitem.WF_Instance.OrgUnitID",
        "WW_ORGUNIT_CODE": "[&1].WF_Workitem.WF_Instance.OrgUnitCode",
        "WW_DOMAIN_CODE": "[&1].WF_Workitem.WF_Instance.WFinstanceSubtype",
        "ACCOUNT_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].ReferenceID",
        "TRANSACTION_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].ReferenceID",
        "CHECK_NAME": "[&1].WF_Workitem.WF_Instance.SubScenarioName",
        "#null": ["[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].ApplicationId", "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].ApplicationId"],
        "#1": ["[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].External_Data_Reference_Type_Dict[0].ReferenceTypeId", "[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].ReferenceTypeId"],
        "#2": ["[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].External_Data_Reference_Type_Dict[0].ReferenceTypeId", "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].ReferenceTypeId"],
        "#Account_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].External_Data_Reference_Type_Dict[0].Name",
        "#Transaction_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].External_Data_Reference_Type_Dict[0].Name",
        "#Account Type - ID stored is the Account_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[0].External_Data_Reference_Type_Dict[0].Description",
        "#Transaction Type - ID stored is the Transaction_ID": "[&1].WF_Workitem.WF_Instance.External_Data_Reference[1].External_Data_Reference_Type_Dict[0].Description",
        "#TM": "[&1].WF_Workitem.opDomain",
        "#AM": "[&1].WF_Workitem.SourceSystem",
        "#ALERT": "[&1].WF_Workitem.WF_Instance.WFinstanceType",
        "CUSTOMER_TYPE_CODE": {
          "*": {
            "P": {
              "#NATURAL PERSON": "[&4].CUSTOMER_TYPE_CODE[]"
            },
            "C": {
              "#ORGANIZATION": "[&4].CUSTOMER_TYPE_CODE[]"
            }
          }
        },
        "CUSTOMER_ID": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Customer[&].CustomerID"
        },
        "CUSTOMER_SEGMENT": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Customer[&].CustomerSegment"
        },
        "REASON_SRC_UNIQUE_ID": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].SRC_ID"
        },
        "REASON_NAME": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].ScenarioName"
        },
        "REASON_SCORE": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].DetectionScore"
        },
        "REASON_TIME_PERIOD": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].ReasonTimePeriod"
        },
        "REASON_DESCRIPTION": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].ReasonDescription"
        },
        "DATASOURCE_ACC_ID": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].SRC_AccountID"
        },
        "DATASOURCE_RECORD_ID": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].SRC_TransactionID"
        },
        "RISK_LEVEL": {
          "*": {
            "Low": {
              "#LOW": "[&4].RISK_LEVEL[]"
            },
            "Medium": {
              "#MEDIUM": "[&4].RISK_LEVEL[]"
            },
            "High": {
              "#HIGH": "[&4].RISK_LEVEL[]"
            }
          }
        },
        "EVENT_TIMESTAMP": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].DetectionTimeStamp"
        },
        "LINKED_ENTITY_KEY": {
          "*": "[&2].WF_Workitem.WF_Workitem_Link[&].LinkedEntityKey"
        },
        "LINKED_ENTITY_NAME": {
          "*": "[&2].WF_Workitem.WF_Workitem_Link[&].LinkedEntityName"
        }
      }
    }
  },
  {
    "operation": "default",
    "spec": {
      "*": {
        "QUEUE_FASTTRACK_FLAG": "NO",
        "WF_Workitem": {
          "InvLifecycleStatus": null,
          "WF_Linked_References": {
            "Global_ID": null,
            "Local_ID": null,
            "SourceRef": null,
            "RelationshipType": null
          },
          "WF_Instance": {
            "WFI_Customer[]": {
              "*": {
                "CustomerTypeCode": null
              }
            },
            "WFI_Reasons[]": {
              "*": {
                "CustomerRiskLevel": null
              }
            }
          }
        }
      }
    }
  },
  {
    "operation": "remove",
    "spec": {
      "*": {
        "ALERT_KEY": ""
      }
    }
  },
  {
    "operation": "modify-overwrite-beta",
    "spec": {
      "*": {
        "WW_ORGUNIT_ID": "=toString",
        "WF_Workitem": {
          "GlobalID": "=concat(@(1,SourceSystem),'',@(1,opDoamin),'',@(1,WF_Instance.WFinstanceType),'',@(1,WF_Instance.InstanceID))"
        }
      }
    }
  },
  {
    "operation": "shift",
    "spec": {
      "*": {
        "*": "[#2].&",
        "QUEUE_FASTTRACK_FLAG": {
          "NO": {
            "#NO": "[&3].WF_Workitem.WF_Instance.FastTrack"
          },
          "1": {
            "#YES": "[&3].WF_Workitem.WF_Instance.FastTrack"
          },
          "0": {
            "#NO": "[&3].WF_Workitem.WF_Instance.FastTrack"
          }
        },
        "CUSTOMER_TYPE_CODE": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Customer[&].CustomerTypeCode"
        },
        "RISK_LEVEL": {
          "*": "[&2].WF_Workitem.WF_Instance.WFI_Reasons[&].CustomerRiskLevel"
        }
      }
    }
  },
  {
    "operation": "sort"
}
]

Solution

  • I am not able to understand the full logic but this will help you resolve your issue.

    [
      {
        "operation": "cardinality",
        "spec": {
          "*": {
            "WF_Workitem": {
              "WF_Instance": {
                "WFI_Customer": "ONE",
                "WFI_Reasons": "ONE"
              }
            }
          }
        }
      }, {
        "operation": "cardinality",
        "spec": {
          "*": {
            "WF_Workitem": {
              "WF_Instance": {
                "WFI_Customer": "MANY",
                "WFI_Reasons": "MANY"
              }
            }
          }
        }
      }
    ]
    

    You need to remove the duplicates from the WFI_Reasons & WFI_Customer arrays so with cardinality 1st I am picking 1st object from respective array that to convert into single object and then converting it back into an array with same operation.

    Hope this resolves your query.