简体   繁体   中英

How to eliminate escape character in Dataweave while transforming to CSV in Mule?

I have a dataweave in the mule flow that transforms the pojo to CSV. So one of the fields in the Pojo is having the value as : "abc,def"

So when dataweave gets transformed to CSV, the response is abc\\,def. The default escape character is being added.

Please let me know how do we get rid of this escape character and have the csv value as : abc,def

Thank you.

By default DataWeave will escape comma to avoid ambiguity/data-error. For example:

column1,column2,column3
abc,def,1234567,xxxyyyz

What is the value of column2, def or 1234567 ?

In order to keep the comma character, then there are two other options:

  1. Change the CSV separator with another character, eg: |. Then apply the following code: %output application/csv separator="|" . It will produce the result as: abc,def|1234567|xxxyyyz
  2. Wrap the value inside quote characters, eg: "abc,def". Then apply %output application/csv quoteValues=true . It will produce: "abc,def","1234567","xxxyyyz"

我发现以下代码将消除DW中的转义字符:

%output application/csv header=true, escape="null"

Late answer but I feel it might be useful. If you want to purely remove the escape character, use:

%output application/csv escape = "" 

This obviously introduces problems, because you will have an extra comma in your csv as mentioned by sulthony h.

column1,column2,column3
abc,def,1234567,xxxyyyz

My solution was to remove the escape char and hardcode quotes onto the string:

%output application/csv escape = ""     
outputField: "\"" ++ inputField ++ "\"" as String

This produces:

"abc,def",1234567,xxxyyyz

So you might need to handle this downstream depending on how tightly you are going to parse it.

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