mapString

mapString(@StreamCapable text: String, mapper: (character: String, index: Number) -> String): String

Applies an expression to every character of a string.

Introduced in DataWeave version 2.4.0.

Parameters

Name Description

text

The string to map.

mapper

Expression that applies to each character ($) or index ($$) of the text string and returns a string.

Example

This example redacts sensitive data from a string.

Source

%dw 2.0
import * from dw::core::Strings
output application/json
---
{ balance: ("\$234" mapString if (isNumeric($)) "~" else $) }

Output

{
  "balance": "$~~~"
}

mapString(@StreamCapable text: Null, mapper: (character: Nothing, index: Nothing) -> Any): Null

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

Introduced in DataWeave version 2.4.0.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub