XML JSON Transformer service

The XML JSON Transformer service converts the XML or JSON input data to the desired format.

The following table provides an overview of the XML-JSON Transformer service:

System Name

xmljsontransformer

Graphical Process Modeler (GPM) category

All Services

Description

Leverages the Sterling B2B Integrator Workflow manager (Business Processes) to convert XML or JSON input data to the desired format.

Business usage

Coverts the input data from JSON to XML and vice-versa.

Preconfigured?

No. The system invokes the BP.

Requires third-party files?

Yes. The json-20170516.jar file is used as a third-party file.

Platform availability

All supported Sterling B2B Integrator platforms

Related services

None

Application requirements

None

Initiates business processes?

Yes

Invocation

The XML-JSON Transformer service is included in a predefined xmljsontransformer business process.

Business process context considerations

JSON to XML conversion:

Input Type = JSON

Output file = output.xml

XML to JSON conversion:

Input Type = XML

Note: In case of XML as an Input, the angular brackets must be replaced with escape characters as follows:

1. ‘<’ with ‘&lt;’

2. ‘>’ with ‘&gt’

For example: &lt;tag&gt;tagdata&lt;tag&gt;

Output file = output.json
Note:

The result of the xmljsontransformer service is stored in output.xml file in the <install_dir>/noapp/bin folder. This service does not add XML headers in the output file. It converts the JSON object body to XML body and is not a well formed XML file with headers.

Returned status values

The desired data format (XML or JSON) is stored in the output.xml file in the install_dir/noapp/bin directory and also in the BP process data.

Restrictions

None

Persistence level

None

Testing considerations

None

You can give the input for the service either using a business process or using a text file.

Using a business process

Sample business process to convert input data from XML to JSON:

<process name="xmljsontransformer">
  <sequence>
    <operation name="Request">
    <participant name='xmljsontransformer'/> 
    <output message='xout'>
    <assign to='input'>&lt;hello&gt;world&lt;/hello&gt;</assign>
    <assign to='inputtype'>XML</assign>  
    <assign to='outputpath'>output.json</assign>
    <assign to='.' from='*'/> 
    </output>
    <input message="xin">
    <assign to='.' from='*'/>
    </input>
    </operation>
 </sequence>
</process>
Process Data:

Process Name: xmljsontransformer                Instance ID: 267252
Service Name: xmljsontransformer

<?xmlversion="1.0" encoding="UTF-8"?>
<ProcessData>
<input_type>XML</input_type>
<input><hello>world</hello></input>
<Output>{"hello":"world"}</Output>
</ProcessData>
Sample business process to convert input data from JSON to XML:

<process name="xmljsontransformer">
  <sequence>
    <operation name="Request">
    <participant name='xmljsontransformer'/> 
    <output message='xout'>
    <assign to='input'>{"student":{"name":"XYZ","age":"22"}}</assign>
    <assign to='inputtype'>JSON</assign> 
    <assign to='outputpath'>output.xml</assign> 
    <assign to='.' from='*'/> 
    </output>
    <input message="xin">
    <assign to='.' from='*'/>
    </input>
    </operation>
 </sequence>
</process>
Process Data:

Process Name: xmljsontransformer                Instance ID: 267252
Service Name: xmljsontransformer

<?xmlversion="1.0" encoding="UTF-8"?>
<ProcessData>
<input_type>JSON</input_type>
<input>input'>{"student":{"name":"XYZ","age":"22"}}</input>
<Output><student><name>XYZ</name><age>22</age></student></Output>
</ProcessData>

Using a text file

Note: The business process definition changes if you provide the input using a text file.

Input.txt

{"certificate":{"certName":"Demo","certData":"demodata"}}

Sample business process to convert input data from JSON to XML by providing input through text file:

<process name="xmljsontransformer">
<sequence>
<operation name="Request">
<participant name='xmljsontransformer'/>
<output message='xout'>
<assign to='.' from='PrimaryDocument/@SCIObjectID'></assign>
<assign to='inputtype'>JSON</assign>
<assign to='outputpath'>output.xml</assign>
<assign to='.' from='*' />
</output>
<input message="xin">
<assign to='.' from='*' />
</input>
</operation>
</sequence>
</process>

Input.txt

<hello>World</hello>

Sample business process to convert input data from XML to JSON by providing input through text file:

<process name="xmljsontransformer">
<sequence>
<operation name="Request">
<participant name='xmljsontransformer'/>
<output message='xout'>
<assign to='.' from='PrimaryDocument/@SCIObjectID'></assign>
<assign to='inputtype'>XML</assign>
<assign to='outputpath'>output.json</assign>
<assign to='.' from='*'/>
</output>
<input message="xin">
<assign to='.' from='*'/>
</input>
</operation>
</sequence>
</process>