Skip to main content
Version: 4.14.7

XML to JSON Current component

The XML to JSON Current component provides a direct conversion from XML format to the JSON format.

Configuration

It has the following configuration options:

Keep in mind that each enabled option could take some extra time to complete the transformation.

Keep strings?

Options

  • yes
  • no (default)

Description

By default the component tries to infer the type of the value and generates it is a string, number or boolean. When you set this option to yes it just transforms all the values to a string by setting double quotes("") around it.

Remark

When used in combination with Has types? set to yes, types set with type attributes still work so you get a combination of both options. Everything will be a string except the values you change with the type attributes.

Example

Notice the difference for the age of the drivers. When no is selected they are transformed as numbers. When yes is selected they are transformed into strings.


<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers>
<Driver>
<Name>Max Verstappen</Name>
<Age>19</Age>
</Driver>
<Driver>
<Name>Nico Hulkenberg</Name>
<Age>30</Age>
</Driver>
</Drivers>
<Teams>
<Team>
<Name>Redbull Racing</Name>
<Principal>Christian Horner</Principal>
</Team>
<Team>
<Name>Renault</Name>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
</Team>
</Teams>
</Formula1>

Remove namespaces?

Options

  • yes
  • no (default)

Description

When you set this option to yes it will remove all namespace attributes and prefixes from the resulting JSON. The removed namespaces and its prefixes will also be mentioned in the flow log.

Example


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<h:table xmlns:h="http://www.dovetail.world/TR/html4/">
<h:tr>
<h:td>Apples</h:td>
<h:td>Bananas</h:td>
</h:tr>
</h:table>
<f:table xmlns:f="https://www.dovetail.world/furniture">
<f:name>African Coffee Table</f:name>
<f:width>80</f:width>
<f:length>120</f:length>
</f:table>
</root>

Remove root object?

Options

  • yes
  • no (default)

Description

When you set this option to yes it will remove the root object from the resulting processed JSON.

Example


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<person>
<name>John Johnson</name>
<age>19</age>
</person>
<person>
<name>John Foo</name>
<age>30</age>
</person>
<person>
<name>John Doe</name>
<age>30</age>
</person>
</root>

Has Types?

Options

  • yes
  • no (default)

Description

When you set this option to yes you can add type attributes to your XML elements which determine the types of the values of these elements in the resulting JSON. The available types are string, number, boolean and array. When an unrecognized type is used it will add a warning in the flow logs and use the type string.

When a type is used that is not supported this will be logged in the log as a warning and the type string will be used.

Simple example


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<person>
<name>John Johnson</name>
<age type="string">19</age>
</person>
<person>
<name>John Foo</name>
<age type="string">30</age>
</person>
<person>
<name>John Doe</name>
<age type="string">30</age>
</person>
</root>

Example with array types


<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers>
<Driver type="array">
<Name>Max Verstappen</Name>
<Age>19</Age>
</Driver>
<Driver type="array">
<Name>Nico Hulkenberg</Name>
<Age>30</Age>
</Driver>
</Drivers>
<Teams type="array">
<Team type="array">
<Name>Redbull Racing</Name>
<Principal>Christian Horner</Principal>
</Team>
<Team type="array">
<Name type="string">Renault</Name>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
</Team>
</Teams>
</Formula1>

When the type and value do not match

Prerequesites

To enable this option, the Has types? option should be set to yes.

Options

  • keep the original value (default)
  • set the value to null
  • go to the error route

Description

This option determines how a mismatch between the type and value of an XML element is handled.

Example


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<person>
<name type="number">John Johnson</name>
<age>19</age>
</person>
<person>
<name type="number">John Foo</name>
<age>30</age>
</person>
<person>
<name type="number">John Doe</name>
<age>30</age>
</person>
</root>

When go to the error route is selected it will log the following error in the logs and go to the error route:


world.dovetail.common.exception.JsonTypeException: There was a mismatch between
a specified type and the value. Type is 'number' and the value is 'John Johnson'.

Remarks

XML attributes

XML attributes are put in an object as a key value pair were the key is prefixed with a @ symbol to indicate it was an XML attribute. The value if the XML node will also be put in the same object with the key jsonContent.

Example


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<root>
<person>
<name realName="true">John Johnson</name>
<age>19</age>
</person>
<person>
<name realName="false">John Foo</name>
<age>30</age>
</person>
<person>
<name realName="false">John Doe</name>
<age>30</age>
</person>
</root>