JSON to XML in Mule
A Transformer prepares a message to be processed through a Mule flow by enhancing or altering the message header or message payload. For example, if the message source that triggers your flow receives data in XML format, but a downstream message processor requires JSON-formatted data, one or more transformers positioned between the message source and the message processor can achieve the necessary translation. (Since no XML-to-JSON transformer exists, this particular example calls for a XML-to-Object transformer chained to an Object-to-JSON transformer.)
Mule Studio provides a set of standard transformers to handle the most common data transformation scenarios. Typically, these pre-packaged processors require minimal configuration. However, if your particular use case requires special settings, you can open the Properties pane for the particular transformer have selected, then modify the default configuration using the drop-down lists or text-entry fields.
Here we are using JSON to XML convertor in mule 3 in Anypoint studio 6.2
JSON to XML convertor converts incoming JSON payload to XML payload
Below is the basic flow of JSON to XML convertor.
HTTP Listener Configuration :
path : /jsontoxml
We not need to to configure anything in JSON to XML convertor.
url : http://localhost:8085/api/jsontoxml
method : POST
input :
output :
Here you can see,
Only the first element is shown as output.
It is important to keep in mind that JSON and XML is not 1 is to 1 compatible, and also, JSON to XML transformer component relies on Staxon's JSON to XML conversion.
To workaround this issue, we must define a root element on our JSON input payload.
Input :
Output :
No comments:
Post a Comment