Fixed Width to JSON Transformation in Mule 4
Transform message is used to convert fixwidth to json.
Flow:
In transform message component, select fixwidth and
map data accordingly as shown below:
Json file metadata settings in transform message
component:
Connect both input and output metadata:
In set payload we need to set path of schema as shown
below:
Method: POST
Input:
Output:
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="http://www.mulesoft.org/schema/mule/http"
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="55dee739-0788-4599-9a80-d276443bb26f" >
<http:listener-connection host="0.0.0.0" port="8085" />
</http:listener-config>
<flow name="test_fixwidthtojsonFlow" doc:id="4bde0cb2-0443-4d71-a831-e0dba5a6dca1" >
<http:listener doc:name="Listener" doc:id="9158e7fc-8913-44f0-950a-464a56948942" config-ref="HTTP_Listener_config" path="/fix"/>
<set-payload value="#[payload]" doc:name="Set Payload" doc:id="43e843b7-6d3a-46b3-803f-de992150507f" mimeType="application/flatfile; schemapath=input.ffd"/>
<ee:transform doc:name="Transform Message" doc:id="9244ace0-abf9-42cd-bb66-761f53cb67ad" >
<ee:message >
<ee:set-payload ><![CDATA[%dw 2.0
output application/json
---
payload map ( payload01 , indexOfPayload01 ) -> {
id: payload01.ID,
age: payload01.AGE
}]]></ee:set-payload>
</ee:message>
</ee:transform>
</flow>
</mule>
No comments:
Post a Comment