DataWeave Interview Question: Compare IDs From Two Arrays and Create a New Array
This article will help you practice your DataWeave skills in MuleSoft. We're going to compare IDs from two arrays of objects and create a new array.
Join the DZone community and get the full member experience.Join For Free
This article will help you practice your DataWeave skills in MuleSoft. Let's get started.
Let's talk about the solution now. We are going to achieve this in multiple steps as follows:
In step 1, we will store the second input into the
Step 1 Code:
In step 2, we will first apply a map to the payload.
After that, we will apply a map on the
input2 variable inside our previous map.
After that, we will check to create the desired output if the ID of the payload matches the ID of
If the condition is false then we will use
Step 2 Code:
Step 2 Output:
In the final step, we are applying
flatten to the whole output and using a filter to show records that are not null.
Step 3 Code:
Hope this helps improve your DataWeave skills. I am not an expert on DataWeave. I am just sharing what I can solve. Comments are welcome. Thanks.
Opinions expressed by DZone contributors are their own.