0

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

  • 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 Aug 30 '18 at 01:25
  • 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 Aug 30 '18 at 19:31

1 Answers1

0

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
}
Clinton Murdoch
  • 453
  • 4
  • 9
  • Tried it but getting error - Message : "You called the function 'Value Selector' with these arguments: 1: Binary ("{\n \"id\": 123,\n \"name\": \"ABC\",\n \"communication\": \...) 2: Name ("id") But it expects one of these combinations: (Array, Name) (Array, String) (Date, Name) (DateTime, Name) (LocalDateTime, Name) (LocalTime, Name) (Object, Name) (Object, String) (Period, Name) (Time, Name) 5| MemberId : payload01.id, ^^^^^^^^^^^^ Trace: at main (line: 5, column: 16)" evaluating expression: "%dw 2.0 – user3563965 Aug 31 '18 at 15:22
  • You need to get that input properly formatted. Where does that input come from? Currently it is a list of JSON formatted strings, rather than a proper JSON array. – Clinton Murdoch Sep 04 '18 at 06:31
  • i am getting it as list of strings in Batch Aggregator component. – user3563965 Sep 05 '18 at 13:49