Copybook to json Conversion in Mule 4
This data format conversion
COPYBOOK to JSON in dataweave is
done by Transform Message component.
Flow of copybook to json:
File structure:
In.ffd is copybook schema
form: COPYBOOK
id: 'in'
name: 'in'
values:
- { name: 'id', usage:
M, type: String, length: 1 }
- { name: 'name',
usage: M, type: String, length: 6 }
file.json is output json file
[{
"id":1,
"name":"kamal"
}]
Transform message component
settings:
Method: POST
Input:
Output:
XML project code:
<?xml version="1.0"
encoding="UTF-8"?>
<mule xmlns:db="http://www.mulesoft.org/schema/mule/db"
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/db
http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
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:listener-config name="HTTP_Listener_config"
doc:name="HTTP Listener config" doc:id="60df71b3-0696-4625-8326-3d34359edb3a"
>
<http:listener-connection host="0.0.0.0"
port="8085" />
</http:listener-config>
<flow name="test_copybooktojsonFlow"
doc:id="cd91a81b-bb0b-46e2-92a4-8ba25b774f3c"
>
<http:listener doc:name="Listener"
doc:id="c5eede57-273d-4225-8b1a-8c1139ef65ab"
config-ref="HTTP_Listener_config" path="/copy"/>
<set-payload value="#[payload]" doc:name="Set Payload" doc:id="2cd10f7c-15ee-4d84-bde4-c94e5d629d14"
mimeType="application/flatfile; schemapath=in.ffd"/>
<ee:transform doc:name="Transform
Message" doc:id="ea3d4dba-bf3c-44db-a61f-92f3f0f50ab4"
>
<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>
</flow>
</mule>
No comments:
Post a Comment
If you have any doubt, please let me know