MulesoftDataweave Function : Pluck and mapObject
1. What is the use of Pluck function in DW 2.0 ?
Just to explain the pluck in DW 2.0 :
- It is used to Map specified Object into an Array.
- The function contains three parameters : Key, Value and Index, where Index is Optional.
Below is the example of Pluck that iterates over the JSON payload (Object) to invert each key, value and index and returns the output as an Array.
(In the examples, DataWeave playground is used (web browser based editor for creating dataweave scripts) to mock input payloads to run transformations and preview the output.)
The same function can be used with Anonymous parameters : $, $$, $$$
Where , Index : $$$,
Key : $$,
Value : $
Below is the example for pluck function with anonymous parameters.
2. mapObject :
The Only difference between Pluck and mapObject is that mapObject returns an Object instead of an Array.
Below is the example of Pluck that iterates over the JSON payload (Object) to invert each key, value and index and returns the output as an Object.
In this way, you can use pluck and mapObject functions that iterated over an Object using DataWeave 2.0
Hope this article helps you to understand basic concept Pluck and mapObject in Mule 4 !
Happy Experience!
-Rutuja Gupta
Congrats on the first blog!!
Associate Director - Integration and Data AI/ML| Principal Technical Architect | MuleSoft Trainer| MCPA | MCIA | AWS Associate Architect| Enterprise Architecture | Digital Transformation | Gen AI Expert
3yGood work
Performance Marketer | Google ads Strategist | LDCE | St. Marian | Corporate Event Planner & Manager
3yGreat Job Rutuja Gupta. Keep it up. !