JSON to XML transformation in Mule
Today to use the json-to-xml-transformer to transform a
json message to xml but have not been able to find
documentation on its use. I don't need any transformation
of the data, simply turning the json properties into xml
tags. When I attempt to use the transformer, all I get out
is the first element from the json.
Input JSON:
if we consider the following
{
"root": {
"name": "Helen",
"fullname": "Rich",
"address": "100 MAIN ST",
"shipToZip": "16684",
"lineInfo": [
{
"lineNumber": "10",
"product": "MAT203"
}
]
}
}
Output:
<?xml version='1.0'?>
<root>
<name>Helen</name>
<fullname>Rich</fullname>
<address>100 MAIN ST</address>
<shipToZip>16684</shipToZip>
<lineInfo>
<lineNumber>10</lineNumber>
<product>MAT203</product>
</lineInfo>
</root>
Flow:
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:json=http://www.mulesoft.org/schema/mule/json
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/documentatio
n"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/json
http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd
http://www.mulesoft.org/schema/mule/http
http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-
current.xsd
http://www.mulesoft.org/schema/mule/core
http://www.mulesoft.org/schema/mule/core/current/mule.xsd">
<http:listener-config name="HTTP_Listener_Configuration"
host="0.0.0.0" port="8081" doc:name="HTTP Listener
Configuration"/>
<flow name="TestFlowJsonToXml" >
<http:listener config-
ref="HTTP_Listener_Configuration" path="/test"
doc:name="HTTP"/>
<json:json-to-xml-transformer mimeType="text/xml"
doc:name="JSON to XML" ignoreBadInput="true"/>
</flow>
</mule>
Transformation jsontoxmlesb

Transformation jsontoxmlesb