Deep Dive Into DataWeave Pluck Operator
See a deep dive into DataWeave pluck operator with examples and videos.
Join the DZone community and get the full member experience.Join For Free
The pluck operator is useful for mapping the object into the array, and it returns the array of values, keys, and indexes of the object.
$ will return values, $$ will return keys and $$$ will return indexes.
We have a list of car objects in a single JSON, but we need to convert that car object into an array of cars or a list of cars in a single array. We can use the pluck operator to achieve this as shown below.
We need to convert the car object into an array of cars and filter those cars having the color red. In this case, we can use the pluck operator with a filter to achieve this as shown below.
We are getting address as a Object in the JSON message but destination is expecting address in single field. In this case, we can use the pluck operator with joinBy to achieve this as shown below.
joinBy merges an array into a single string value and uses the provided string as a separator between each item in the list.
DataWeave Transformation (Pluck and Reduce) With MuleSoft
Reading Attachments in MuleSoft | MultiPart | Form-Data | Pluck
Now, you know how to use the pluck operator with MuleSoft DataWeave.
Opinions expressed by DZone contributors are their own.