Skip to main content

Hi All,

 

I'm getting data as the following CSV with comma(,) separator where the EmployeeInformation is in JSON format

 

Name,Date,EmployeeInformation

DEF,2022-05-15,NULL

MNO,2022-04-31,NEWLY GRADUATED

ABC,2022-06-21,{"Previouscompany":"xyz","ID":"12345","department":"IT Communications","salary":"25000"}

 

and we have to populate the output in CSV format but with '|' separator

 

and the expected output should be like the following (the entire JSON data should be in one column)

 

Name,Date,EmployeeInformation

DEF|2022-05-15|NULL

MNO|2022-04-31|NEWLY GRADUATED

ABC|2022-06-21|{"Previouscompany":"xyz","ID":"12345","department":"IT Communications","salary":"25000"}

 

Thanks in Advance

23 respostas
  1. 21 de jun. de 2022, 13:13

    Hi @Phani Kakuleti​ !

     

    Do you know if it's possible to ask the source of the csv to escape the "," in the file they send you

    Because if they can something like this:

    Hi @Phani Kakuleti​ ! Do you know if it's possible to ask the source of the csv to escape the 

    It will simplify the required DWL to solve the issue:

     

    image 

    And if that's not possible, then you need to process the csv as a string and perform the following operations:

    image 

    %dw 2.0

    output application/csv separator='|'

    var replacedPayload = payload replace '","' with '"\,"'

    var parsedPayload= read(replacedPayload, 'application/csv')

    ---

    parsedPayload

     

    Hope it helps!

     

    Good luck!!

     

    Juan Cruz Basso

0/9000