Search code examples
muledataweavemulesoftmule4

How to solve parse issues when a CSV has a field content escaped with double quotes


The input is received from a Salesforce Bulk API query.

INPUT

"RecordTypeId","Name","Description"
"AAA","Talent 2022 - Skills Renewal - ABC","DF - 14/03 - Monty affirmed that the ""mastercard approach"" would best fit in this situation. I will connect (abc, def, ghi) and the confirm booking tomorrow (15/03)"

SCRIPT:

%dw 2.0
output application/csv separator=",", ignoreEmptyLine=false, quoteValues=true, quoteHeader=true, lineSeparator="\r\n"
---
payload

OUTPUT:

"RecordTypeId","Name","Description"
"AAA","Talent 2022 - Skills Renewal - ABC","DF - 14/03 - Monty affirmed that the , def, ghi) and the confirm booking tomorrow (15/03)"

Expected OUTPUT: The column description has " and , in it and therefore some description content is getting lost and some is getting shifted to different columns. I need entire description value in one column


Solution

  • It looks like your payload is using " as escape character. By default DataWeave expects \ as the escape character for CSV, so you will need to specify the escape character explicitly while reading your input, after which DataWeave should be able to read the completely description as a single value.

    For example the below DataWeave shows how you can use the input derivative to read your csv correctly. I do not know what exactly is your expected output so I am just giving an example that writes the value of description as text

    %dw 2.0
    input payload application/csv escape='"'
    output text
    ---
    payload[0].Description
    

    The output of this will is

    DF - 14/03 - Monty affirmed that the "mastercard approach" would best fit in this situation. I will connect (abc, def, ghi) and the confirm booking tomorrow (15/03)