CSV to JSON Conversion in Mule 4

CSV to JSON in Mule 4

We can use dataweave transformation to transform data from csv file into json format.

flow of csv to json transformation : 

File structure:






Transform Message settings:


Method: GET

    "id": 1,
    "name": "Rahul"
    "id": 2,
    "name": "Rohit"

XML Project code:

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core"
       xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd">
       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="d71ebfb4-29de-4b40-a68c-894ea43753cb" >
              <http:listener-connection host="" port="8085" />
       <file:config name="File_Config" doc:name="File Config" doc:id="5d903a69-59d7-45e5-9ced-377701de8f66" >
              <file:connection workingDir="C:\AnypointStudio\studio-workspace\test_csvtojson\src\main\resources" />
       <flow name="test_csvtojsonFlow" doc:id="0748bbb1-6b8b-41fc-bf4d-68421cc8114c" >
              <http:listener doc:name="Listener" doc:id="f8befbea-1db9-4fee-b579-5c85601a0034" config-ref="HTTP_Listener_config" path="/csvtojson"/>
              <file:read doc:name="Read" doc:id="499da6ab-eb90-4389-9a8b-3ffe9ea02a0e" config-ref="File_Config" path="C:\AnypointStudio\studio-workspace\test_csvtojson\src\main\resources\new.csv"/>
              <ee:transform doc:name="Transform Message" doc:id="f520f96a-a4ac-4253-ab7b-0e87b91bb689" >
                     <ee:message >
                           <ee:set-payload ><![CDATA[%dw 2.0
input payload application/csv
output application/json
payload map ( payload01 , indexOfPayload01 ) -> {
       id: payload01.empid as Number,
       name: payload01.name
              <logger level="INFO" doc:name="Logger" doc:id="343ae37b-5177-4bd8-9190-a30739b5357f" message="#[payload]"/>

© 2020 goformule.com

Share on :

Mule 4:

XML to JSON in mule 4 Web service consumer VM Validation in Mule 4 Until Successful
Sub flow Set Variable & Remove Variable Set Transaction ID Scatter Gather Round Robin
Consume Restful Service CRUD in Mule 4 Parse Template Object to JSON Load Static Resource
JSON to XML Invoke Idempotent Filter ForEach Flat file to JSON
Fixwidth to JSON First Successful File Execute Error Handling
Email Dynamic Evaluate Custom Business Event CSV to JSON Copybook to JSON
Choice Router Async RabbitMQ

Mule 3:

Database Connector Async CXF Attachement XSLT
Mongo DB Cache scope Custom Business Event Gzip Compress Expression
SMTP For Each Expression Javascript Filter Reference
Salesforce Message Enricher Groovy Parse Template Idempotent
VM Poll Invoke Ruby Message
Webservice consumer Python Transformer reference Message Property Not
Collection Aggregator First Sucessful Catch Exception Strategy Reference Exception Strategy Or
Choice Message Chunk Aggregator Choice Exception Strategy Global Exception Strategy Schema Validation
Custom Aggregator Scatter Gather Custom Exception Strategy Batch Processing MEL
M Unit RAML Map Operator API Mocking Dataweave