Gopal
Gopal

Reputation: 11

removing backslashes in mule 4 dataweave transformation

I am fetching data from SQL Server Database and transforming it into JSON in Mule 4. My input has a single backslash and converted to double backslashes. I only need a single backslash in my output.

Input example:

abchd\kdgf

Output is:

"abchd\\kdgf"

It should be:

"abchd\kdgf"

Anyone can help with this data weave transformation?

Upvotes: 0

Views: 4946

Answers (2)

Star
Star

Reputation: 1503

Here single slash treated internally as double slash. Try the dataweave expression like below

payload replace /([\\])/ with ("")

enter image description here

Hope it helps

Upvotes: 1

aled
aled

Reputation: 25664

In JSON strings the backslash character is the escape character, and has to be escaped itself to represent a single backlash. That's how JSON works, it is not a Mule issue.

Upvotes: 1

Related Questions