JSON TO CSV Conversion In Mule 4

 

In this tutorial we will demonstrate how can we perform json to csv conversion in mule 4 and perform some more operations while converting to CSV

UseCase-1

Sample JSON

{
"First Name": "John",
"Last Name": "Right",
"Sex": "Male",
"EmployeeID": "123",
"email_address": "[email protected]",
"country": "India",
"date_of_birth": "17-07-1966"
}

 

Create a sample mule application

JSON TO CSV Conversion In Mule 4

 

Write Transformation to convert json to csv

%dw 2.0
output application/csv quoteValues=true
---
Payload

 

JSON TO CSV Conversion In Mule 4

 

Write file to local directory

JSON TO CSV Conversion In Mule 4

 

Deploy the application and test the flow

JSON TO CSV Conversion In Mule 4

 

CSV File is created in Local Directory

JSON TO CSV Conversion In Mule 4

 

UseCase-2

Now if we don’t want to write the Header we need to write the transform message as shown below

%dw 2.0
output application/csv quoteValues=true,header=false
---
Payload

Deploy the application and see the result below:

 

UseCase-3

Now if we want to change the separator, use the below transformation

%dw 2.0
output application/csv quoteValues=true,header=true,separator="|"
---
Payload

Deploy the application and see the result after opening in Text Pad

 

  
Thank you for taking out time to read the above post. Hope you found it useful. In case of any questions, feel free to comment below. Also, if you are keen on knowing about a specific topic, happy to explore your recommendations as well.
 
For any latest updates or posts on our website, you can follow us on LinkedIn. Look forward to connecting with you there.


Share this:
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments