简体   繁体   中英

Escape “\” backslash from dataweave for csv output Mule

CSV output is generated from java Map in Dataweave, Output response adds "\\" to every "," present within the values. All the map values are added inside the double quotes, ex: map.put('key',"key-Value");

Response Received :

Header1, Header2

1234,ABC \\,text

7890,XYZ \\,text

Expected Response :

Header1, Header2

1234,ABC ,text

7890,XYZ ,text

Header2 should contain "ABC,text" as value without quotes ""

Tried using %output application/csv escape=" ", but this adds extra space to each blank space in the values ie if the value is "ABC XYZ" then output is "ABC XYZ" (2 spaces in between)

Any suggestion will be helpful...

Embedded commas in data in a comma separated value file must be escaped or there is no way to tell those values apart from field separators. If you want some way to have the commas in your CSV file without escaping them, then you need to use a separator other than a comma.

You Expected Response as shown would not be valid, as you have a two field header, but data lines that would be interpreted as having 3 fields, not 2 fields, one with an embedded comma which is what the data has and is shown in the Response Received table.

I've got the same scenario, where we have comma in the data itself, like in your case Header2 .

To solve the issue, I've just added below

%output application/csv quoteValues=true

above solved my problem, and we got the expected output.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM