In DataWeave we can use expressions in strings that will be evaluated and inserted into the string value. This is called string interpolation. The expression must be enclosed in parentheses where the first parenthesis is prefixed with a dollar sign: $(<expression>)
. The expression must return a string value or can be automatically coerced into a string value in order for it to work. The expression can also be a variable.
In the following example we use a variable, selector, the upper
function and a calculation that returns a number that is coerced into a string:
Source
%dw 2.0 var prefix = "Hi" var user = { alias: "mrhaki", name: "Hubert Klein Ikkink"} var count = 41 output text/plain --- "$(prefix), welcome $(user.name) also known as $(upper(user.alias)). You're visitor $(count + 1)."
Output
Hi, welcome Hubert Klein Ikkink also known as MRHAKI. You're visitor 42.
Written with DataWeave 2.4.