0
votes

I have Array of Strings, want to convert it into a csv output in mule 4.1.2. Sample input payload is as below -

[ "{\n "id": 123,\n "name": "ABC",\n "communication": "email"\n}", "{\n "id": 123,\n "name": "ABC",\n "communication": "paper"\n}" ]

I need csv output with columns as

MemberId Person Name Communcation 123 ABC email

1
Can you please edit your question so that the strings are properly formatted? Looks like your quotes are not properly escaped. If I tried to edit myself I'd just be taking a random stab at it. - jerney
following is corrected one - [ "{\n \"id\": \"123\",\n \"name\": \"ABC\",\n \"communication\": \"email\"\n}", "{\n \"id\": \"123\",\n \"name\": \"ABC\",\n \"communication\": \"paper\"\n}" ] - user3563965

1 Answers

0
votes

This is fairly simple using DataWeave

%dw 2.0
output application/csv headerLineNumber = 0 , header = true
---
payload map ( payload01 , indexOfPayload01 ) -> {
    MemberId: payload01.id as String,
    "Person Name": payload01.name,
    Communication: payload01.communication
}