Reputation: 11
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 i.e if the value is "ABC XYZ" then output is "ABC XYZ" (2 spaces in between)
Any suggestion will be helpful...
Upvotes: 0
Views: 2284
Reputation: 11
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.
Upvotes: 1
Reputation: 357
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.
Upvotes: 1