I need to compare two arrays that have different data fields in them. The comparison is based on lets say Id number and if data matches in the two arrays, I need to remove the whole block/row from the array. For example, in the below arrays, I need to compare OrderId(from Array1) and SystemId(from Array2) and if the Ids match the whole block needs to be removed from Array1. Please see sample arrays and output below:
Array1 = [
{
"OrderId": "00111111",
"BillingCountry": "GB",
"CurrencyIsoCode": "GBP",
"PersonEmail": "[email protected]"
},
{
"OrderId": "00222222",
"BillingCountry": "US",
"CurrencyIsoCode": "USD",
"PersonEmail": "[email protected]"
}
]
Array2 = [
{
"SystemId": "00111111"
},
{
"SystemId": "00333333"
},
{
"SystemId": "00444444"
}
]
Output: [
{
"OrderId": "00222222",
"BillingCountry": "US",
"CurrencyIsoCode": "USD",
"PersonEmail": "[email protected]"
}
]
This DataWeave script uses the map function to extract all the SystemId values from Array2. Then, it filters Array1 based on whether the OrderId is contained within the systemIds array. This should exclude elements from Array1 where the OrderId matches any SystemId in Array2.