1
votes

...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.

2

2 Answers

6
votes

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.

2
votes

This may be just because your output is application/dw. Once you switch to application/json or other mime-type the escaping should work correctly.