Contact Us 1-800-596-4880

mask

mask(value: Null, fieldName: String | Number | PathElement): (newValueProvider: (oldValue: Any, path: Path) -> Any) -> Null

Helper function that enables mask to work with a null value.

Introduced in DataWeave version 2.2.2.

mask(value: Any, selector: PathElement): (newValueProvider: (oldValue: Any, path: Path) -> Any) -> Any

This mask function replaces all simple elements that match the specified criteria.

Simple elements do not have child elements and cannot be objects or arrays.

Introduced in DataWeave version 2.2.2.

Parameters

Name Description

value

A value to use for masking. The value can be any DataWeave type.

selector

The PathElement selector.

Example

This example shows how to mask the value of a password field in an array of objects. It uses field("password") to return the PathElement that it passes to mask. It uses with "" to specify the value () to use for masking.

Source

%dw 2.0
output application/json
import * from dw::util::Values
---
[{name: "Peter Parker", password: "spiderman"}, {name: "Bruce Wayne", password: "batman"}] mask field("password") with "*****"

Output

[
   {
     "name": "Peter Parker",
     "password": "*****"
   },
   {
     "name": "Bruce Wayne",
     "password": "*****"
   }
 ]

mask(value: Any, fieldName: String): (newValueProvider: (oldValue: Any, path: Path) -> Any) -> Any

This mask function selects a field by its name.

Introduced in DataWeave version 2.2.2.

Parameters

Name Description

value

The value to use for masking. The value can be any DataWeave type.

fieldName

A string that specifies the name of the field to mask.

Example

This example shows how to perform masking using the name of a field in the input. It modifies the values of all fields with that value.

Source

%dw 2.0
output application/json
import * from dw::util::Values
---
[{name: "Peter Parker", password: "spiderman"}, {name: "Bruce Wayne", password: "batman"}] mask "password" with "*****"

Output

[
   {
     "name": "Peter Parker",
     "password": "*****"
   },
   {
     "name": "Bruce Wayne",
     "password": "*****"
   }
 ]

mask(value: Any, i: Number): (newValueProvider: (oldValue: Any, path: Path) -> Any) -> Any

This mask function selects an element from array by its index.

Introduced in DataWeave version 2.2.2.

Parameters

Name Description

value

The value to mask. The value can be any DataWeave type.

index

The index to mask. The index must be a number.

Example

This example shows how mask acts on all elements in the nested arrays. It changes the value of each element at index 1 to false.

Source

%dw 2.0
output application/json
import * from dw::util::Values
---
[[123, true], [456, true]] mask 1 with false

Output

[
   [
     123,
     false
   ],
   [
     456,
     false
   ]
 ]