Flat File to JSON Transformation in Mule 4

Flat file to JSON Transformation in Mule 4

In Mule 4, flat file to json transformation is done by message transform component.

Flow:

Flat file is read by Read component and transform message transform into json form.
Read component settings:


Transform message settings:




Method: GET

Output:



XML project code:

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" 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/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://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd">
       <file:config name="File_Config" doc:name="File Config" doc:id="13414e42-6406-41f4-aa0c-a067d6a7e954" >
              <file:connection workingDir="C:\AnypointStudio\studio-workspace\test_csvtojson\src\main\resources" />
       </file:config>
       <http:listener-config name="HTTP_Listener_config" doc:name="HTTP Listener config" doc:id="406483f2-4a6f-4656-97ab-d994e2856b9c" >
              <http:listener-connection host="0.0.0.0" port="8085" />
       </http:listener-config>
       <flow name="test_flatfiletojsonFlow" doc:id="c83643ec-75db-4a27-b8e5-6312f0f3793e" >
              <http:listener doc:name="Listener" doc:id="98bbcf94-3c63-4c5f-8a52-62afd89886bf" config-ref="HTTP_Listener_config" path="/flattojson"/>
              <file:read doc:name="Read" doc:id="7e57175d-2216-4b37-a226-01b67f756081" path="C:\AnypointStudio\studio-workspace\test_flatfiletojson\src\main\resources\file.txt" outputMimeType="application/flatfile; schemapath=in.ffd" config-ref="File_Config">
                     <ee:repeatable-file-store-stream bufferUnit="MB" />
              </file:read>
              <ee:transform doc:name="Transform Message" doc:id="668f18c6-e292-471a-81fe-d9caf9f72f90" >
                     <ee:message >
                           <ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload map ( payload01 , indexOfPayload01 ) -> {
       id: payload01.id as Number,
       name: payload01.name
}]]></ee:set-payload>
                     </ee:message>
              </ee:transform>
              <logger level="INFO" doc:name="Logger" doc:id="edbb3267-ad5b-4099-a09f-7f54fda1dd7d" message="#[payload]"/>
       </flow>
</mule>








© 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