DataWeave: The map Function Explained

Main Points:

  • The map function transforms data
  • If iterates over the elements in an array 
  • It applies a transformation to each element
  • Applies only to array input
  • It can only output an array

What Is the map Function Used For?

The map function is used to transform the data contained in an array. It does this by iterating over the elements in the array and applying a transformation to each element. The result of the transformation is collected together and output as an array of transformed elements. If you are familiar with Java 8 functional programming approach, a comparison can be made with the the map() method of the Stream class, find out more in my article Contrast DataWeave and Java mapping operations.

How Is the Transformation Described?

The transformation that is applied to each element is described with DataWeave. For example, to change a text value in the source array use the upper() built in function.