Contact Free trial Login

mapLeafValues

mapLeafValues(Any, (value: Any, path: Path) -> Any): Any

Maps the terminal (leaf) nodes in the tree.

Leafs nodes cannot have an object or an array as a value.

Parameters

Name Description

value

The value to map.

callback

The mapper function.

Example

This example transforms all the string values to upper case.

Source

%dw 2.0
output application/json
---
%dw 2.0
 import * from dw::util::Tree
  output application/json
  ---
 {
     user: [{
         name: "mariano",
         lastName: "achaval"
     }],
     group: "data-weave"
 } mapLeafValues (value, path) -> upper(value)

Output

{
   "user": [
     {
       "name": "MARIANO",
       "lastName": "ACHAVAL"
     }
   ],
   "group": "DATA-WEAVE"
 }

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub