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 inter-operability.

Configuration

Below is the JSONConverter Component Property Sheet (CPS) with Expert Properties (Click icon) enabled.


Figure 1: JSONConverter CPS with Expert Properties enabled

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 ? (Yes/No)

  • If Yes, it converts Input JSON to XML.
  • If No, it converts Input XML to JSON.

Convert JSON To XML ? as 'yes'

This property is used to convert JSON to XML.


Figure 2: Component configuration - To convert JSON to XML

Show JSON types as attributes?

Whether JSON element types should be included as attributes in Output XML or not.

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.

Convert JSON To XML ? as 'no'

If the property value is 'no' it is nothing but to convert XML to JSON


Figure 4: Component configuration - To convert XML to JSON

Skip Namespaces?

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

Remove Namespace Prefix From Elements? (Yes/No)

Whether the namespace prefix from XML elements should be removed when reading for XMLSerializer.

Indent Factor

String Indent value for JSON Object.

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

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 6: Sample Event Process

Sample Input


Figure 7: Sample Input

Output


Figure 8: 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 9: Sample Event Process

Sample Input


Figure 10: Sample Input

Output


Figure 11: 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 JSON convertor and the corresponding XML output can be seen in Display. Here, root of the XML is the same as given in Figure 2. In 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 12: 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.

Adaptavist ThemeBuilder EngineAtlassian Confluence