DataWeave : map()

DataWeave : map()

map() :

The map is a function in Dataweave which iterates over the items in an array and outputs them into a new array.

map(item,index) :

item (default $): it represents the element in the input array list.

index (default $$) : it represents the position of the element the input array list.

map function is only applicable for an arrays

It basically accepts input as a list of items in an array and transforms the items in the array in order to form a new array as an output.

Example 1:

multiplying item with it's index: ex1.PNG

Example 2:

iterating with default symbols ($,$$)

ex1 :

ex3.PNG

ex2:

ex4.PNG

Example 3 :

transforming employee data:
condition 1: employee id as key.
condition 2: value is combination of first and last name.

ex2.PNG

Note : Whenever we are applying map function other than an arrays we get the exception

Example 4:

ex5.PNG

Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.

#mulesoft #dataweave #dw #anypointstudio #mule #muleEsb #map#map()