The JSONConverter component serves the need to convert data from either JSON format to XML format or from XML format to JSON format.

In recent times, JSON format is increasingly being used for serializing and transmitting structured data over a network connection like data transmission between server and a web application. Since JSON format is not widely adopted by all organizations yet, and as most of the data exchange is done through XML in earlier networks which have not deployed JSON, conversion from JSON to XML or vice-versa has become essential for data interoperability.

Configuration

JSONConverter Component Property Sheet (CPS) allows customizing the default configuration settings.


Figure 1: JSONConverter CPS

General configuration

Error Handling Configuration

Click the Ellipsis  button to configure actions to be taken when an exception occurs; the attributes present in the dialog box are:

  • JMS Error
  • Response Generation Error
  • Request Processing Error
  • Invalid Request Error

For descriptions, please refer Error Handling section in Common Configurations page.

Convert JSON To XML ?

  • If yes, it converts Input JSON to XML.
  • If no, it converts Input XML to JSON.

Converting JSON To XML

If the value of the Convert JSON to XML property is set to 'yes', the component converts JSON to XML.


Figure 2: Component configuration to convert JSON to XML

Show JSON types as attributes?

Whether or not to include JSON element types as attributes in Output XML.

Expand Array name to Child Elements ?

Enabling this will copy the parent JSONArray name to its child elements during JSON to XML conversion.

Output XSD Schema

Output port Schema can be provided here using schema editor which opens upon clicking the ellipsis  button. It can be used to generate sample output XML for the component.


Figure 3: Output XSD Schema dialog box

Root Name

This field is used to set the name of root for the converted XML.

Icon
  • To ignore the property, leave it blank.
  • This is an Expert Property.
Element Name

This field is used to set the element name for each object of the array in the converted XML. When an array object in JSON format is converted into XML, each element of the JSON array is split into different XML fields, each with Element Name.

Icon
  • To ignore the property, leave it blank.
  • This is an Expert Property.

Converting XML to JSON

If the value of the Convert JSON to XML property is set to 'no', the component converts XML to JSON.


Figure 4: Component configuration to convert XML to JSON

Skip Namespaces?

Whether or not to skip adding namespace declarations to XML elements while conversion.

Remove Namespace Prefix From Elements? (Yes/No)

Whether or not to remove the namespace prefix from XML elements when reading for XMLSerializer.

Indent Factor

String Indent value for JSON Object.

Icon

This option gets disabled if Formatting JSON is set to "yes".

Input XSD Schema

Input port Schema can be provided here using the schema editor which opens upon clicking the ellipsis  button. It can be used to generate sample input XML for the component. 


Figure 5: Input XSD Schema dialog box

Formatting JSON

Whether to format the JSON text after conversion.

Icon

The Indent Factor property gets disabled when the value is set to "yes".

Skip Root Element?

Whether to skip Root Element while converting from XML to JSON. Determines whether the resulting JSON will start off with a top-most element whose name matches the XML root element.

Example

Icon

Consider the XML string below:

If the property is set to

  • "yes", the string is translated as:

  • "no", the string is translated as:

Icon

The Expert property "Treat empty elements as Non-Array in Json?" which is applicable in XML to JSON conversion is described in the section below.

Expert Properties

To configure expert properties, click the  icon; advanced properties get displayed.

Icon

Expert properties are meant for advanced users; use with caution.


Figure 6: JSONConverter CPS with Expert properties enabled and highlighted

Pre Processing XSL Configuration

Pre Processing XSL configuration can be used to transform request message before processing it. Click the small button on the property to configure the properties.

Icon

Refer to the Pre/Post Processing XSL Configuration section under Common Configurations topic for details regarding XSL configuration. The properties comprising this XSL configuration are:

  • Provide XSL
  • XSLT Engine
  • Transformation source data
  • Set transformation result as

Post Processing XSL Configuration

Post Processing XSL configuration can be used to transform response message before sending it to the output port.

Icon

As mentioned in the above section, refer to the Pre/Post Processing XSL Configuration section under the Common Configurations topic for details regarding XSL configuration.

Process Message Based on Property

The property helps components to skip certain messages from processing.

Icon

Refer the Process Message Based On a Property section under the Common Configurations topic.

Enable Thread Pool

This property is used when there is a need to process messages in parallel within the component, still maintaining the sequence from the external perspective. 

Icon
  • Limit the usage of the Threadpool Configuration property only in circumstances as mentioned above.
  • If sequential processing is not required, please use sessions on the input port.

Set the value of the Enable Thread Pool property to "yes" to configure the Threadpool Configuration properties.


Figure 7: Threadpool Configuration

Pool Size

The number of requests to be processed in parallel within the component. Default value is '1'.

Batch Eviction Interval (in ms)

Time in milliseconds after which the threads are evicted in case of inactivity. New threads are created in place of evicted threads when new requests are received. Default value is '1000'.

Treat empty elements as Non-Array in Json?

If this property is set to 'yes', the microservice treats all empty elements and elements with space as an empty string in Json.

Examples

Icon
Input
Output
Icon

This expert property is applicable in XML to JSON conversion. Hence it appears only when the Convert JSON to XML property is set to "no".


Figure 8: Convert JSON to XML set to 'no'

Functional Demonstration

Scenario1: JSON to XML

This scenario shows how JSONConverter can be used to convert data in JSON Format to XML Format.
Create flow by connecting JSONConverter to Feeder and Display components. Send sample input (valid JSON) to check the response (transformed XML message). Use Configuration from Figure 2. The JSON input is sent from the Feeder and the corresponding XML output can be seen in Display.


Figure 9: Sample Event Process

Sample Input


Figure 10: Sample Input

Output


Figure 11: Sample Output

Scenario 2: XML to JSON

This scenario shows how JSONConverter can be used to convert data in XML Format to JSON Format.

Create flow by connecting JSONConverter to Feeder and Display components. Send sample input (valid XML) to check the response (transformed JSON message). Use Configuration from Figure 4.

The XML input is sent from the Feeder and the corresponding JSON output can be seen in Display.


Figure 12: Sample Event Process

Sample Input


Figure 13: Sample Input

Output


Figure 14: Sample Output

Scenario 3

Create flow by connecting JSONConverter to Feeder and Display components. Send sample input (valid JSON message) to check the response (transformed XML). Use Configuration from Figure 2.

The JSON input with array object is sent from the Feeder to the JSONConverter microservice and the corresponding XML output can be seen in Display. Here, the root of the XML is the same as given in Figure 2. In the output, the root element is set as "abc", which has been given in CPS configuration. Here in "Sample Input", "quantity" is an array object. While converting into XML, each element of the array is stored in "bcd" fields, which has been given in CPS configuration.


Figure 15: Sample Event Process

Sample Input

{"shiporder": { "@orderid": "orderid", "orderperson": "orderperson", "shipto": { "name": "name", "country": "country" }, "item": { "title": "title", "quantity": [12,15,23,45],} }} 

Output

Useful Tips

  • Output port and Input port XSD schemas can be used for mapping transformations for corresponding JSONtoXML and XMLtoJSON conversions.
  • In order to preserve the data type while converting an Input XML to JSON, specify the "type" attribute in the input XML.

    Example

    Icon
    Input
    Output
Adaptavist ThemeBuilder EngineAtlassian Confluence