Search code examples
muledataweavemulesoftmule4

How to append --EOF to CSV file after transforming JSON to CSV in Mule 4


I want to append --EOF at the end of file in CSV after transforming JSON to CSV in Mule Data Weave 2.0

Input:

{ "serialNumber": "ABCD", "asset": "EFGH" }

Output:

ABCD|EFGH

--EOF


Solution

  • Use the write() function to write the output as a string so you can concatenate it to the EOF string that you want.

    Example:

    %dw 2.0
    output text/plain
    ---
    write(payload, "application/csv", {"header":false, "separator" : "|"}) ++ "\n--EOF"