xml to json transformer

XML to JSON Transformer

Version: 17.07

Supported Since: 17.01

What is an XML to JSON Transformer?

An XML to JSON Transformer is a processing element which transforms an XML message payload to a JSON payload.

This transformation is done based on a generic set of rules and hence this processing element is most suitable for simple transformations. For complex transformations based on custom rules, Adroitlogic Data Mapping Tool is recommended.

In order to use this processing element, you must first select the Message Transformation dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Message Transformation dependency.

xml json outports

Out Ports

Next

The message will be sent to this outport if the payload transformation is completed successfully

On Exception

The message will be sent to this outport if the processing element failed to transform the payload due to some reason

Parameters

Starting element

Basic

An optional starting element name to begin transformation from. If this is specified, only the XML part within the specified element will be converted to JSON and set as the new payload of the message. If source payload does not contain such element, the resulting payload will be empty.

This parameter can be specified in either of the following formats.

  • namespace_prefix:local_part

  • local_part

Retain namespace prefixes

Basic

Whether to retain namespace prefixes of xml tags in the JSON keys as well. By default this parameter is set to true.

Key for content

Basic

In case where an XML element has one or more attributes in addition to the textual content, the value of this parameter will be used as the JSON key for the textual content. This parameter is optional and defaults to "value".

For example refer the following sample xml content.

<?xml version="1.0" encoding="UTF-8"?>
<breakfast_menu xmlns="http://www.adroitlogic.org/namespace/adrt">
    <food id="1">
        <name>Belgian Waffles</name>
        <price unit="$">5.95</price>
    </food>
</breakfast_menu>

Notice that in the following converted JSON output, textual content of price element is contained under the key "value", which is the value of this parameter.

{
    "breakfast_menu":{
        "food":{
            "id":"1",
            "name":"Belgian Waffles",
            "price":{
                "unit":"$",
                "value":"5.95"
            }
        }
    }
}

Sample Use Case

In the following use case, the requirement is to read a message with an XML payload from a SFTP server, convert the message payload to JSON and then deliver it to another SFTP endpoint.

xml to json flow
xml to json config

In this flow, the "Processor" outport of SFTP ingress connector is connected to the inport of the XML to JSON Transformer so that the SFTP message received by the connector is handed over to the transformer next. If the processing element is able to transform the payload from XML to JSON successfully, the message with the transformed payload is handed over to the SFTP egress connector, as the "Next" outport of the XML to JSON Transformer is connected to it.

In the case of transformation failure, a log will be generated and then the message flow will complete in an exceptional state, as the "On Exception" outport of the XML to JSON Transformer is connected to a Logger processing element, followed by an Exceptional Flow End element.

In this topic
In this topic
Contact Us