Search code examples
dataweavemulesoft

Mulesoft DataWeave: How to escape $ for quoted string


...I'm using Anypoint Studio 7.6 and writing in DataWeave 2.0

I cannot find the definitive way to include the $ (dollar sign) character in a quoted string.

Here's what I tried:

%dw 2.0
output application/dw
var sign = "\u0024" // unicode dollar sign
type currency = String {format: "$sign ###.00"} // interpolation from previous var
var cost = 100 as currency
---
{
    directly: "a dollar sign like this: \$",
    asdefined: sign,
    indirectly: "This flight, costs $(cost), and is operated by " 
       ++ payload.airline
}

Here's what I got for my trouble:

{
  directly: "a dollar sign like this: \$",
  asdefined: "\$",
  indirectly: "This flight, costs \$ 100.00, and is operated by United"
}

I feel like I'm missing something simple.


Solution

  • Hi There is no problem with what you see it is just that you are using application/dw as output. In that format the $ need to be escaped that is why you see it like that. If you change to application/json they will disappear.