Using pluck() function in DataWeave 2

The pluck() function in DataWeave 2 is a function used to convert the properties and values of these properties of an object into an array of properties, an array of values and an array of indices of those properties.

The syntax of the pluck() function will be:

In particular, index is the order of the properties of the input object, the key is the name of the object’s properties and the value is the value of the properties.

For example, I have a student object with the name attribute. has the value “Khanh” and the age attribute has a value of 30, displayed with mediaType application/xml with the following content:

To return the array of student object properties, I will use the pluck() function as follows:

Result:

Using pluck() function in DataWeave 2

Same for index and value:

Result:

Using pluck() function in DataWeave 2

You can use the characters $, $$ or $$$ instead of value, key and index in order.

for value,

for key and:

for index.

As a result, the following writing way still produces similar results:

Result:

Using pluck() function in DataWeave 2

With this writing, as you can see, we do not need to specify the value, key or index parameters. DataWeave will understand itself and produce similar results.

Chia sẽ bài viết này ...Share on Facebook
Facebook
0Tweet about this on Twitter
Twitter
Share on LinkedIn
Linkedin

Add Comment