Skip to main content
Version: 4.17.4

XML to JSON Simple component

The XML to JSON Simple component allows you to convert XML files into JSON files.

Configuration

The XML to JSON Simple component has the following basic configuration options:

Keep strings?

By default, the component tries to infer the type of each value and converts it into a string, number, or boolean. When this option is set to Yes, all values are transformed into strings, encapsulated in double quotes ("value").

Options

  • Yes
  • No (default)
combination with 'Has types?'

When used in combination with Has types? set to Yes, all values will be treated as strings, except for those explicitly modified using type attributes.

<?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?

Specify whether to remove all namespace attributes and prefixes from the resulting JSON.

Options

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

Specify whether to remove the root object from the JSON output.

Options

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

When set to Yes, this option allows you to define a type attribute in the XML elements, determining the type of their values in the JSON output.

Options

  • Yes
  • No (default)
using types

The available types are string, number, boolean and array. If an unrecognized type is specified, the value defaults to string.

<?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>
<?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 don't match it needs to

Specify how mismatches between an XML element's type and its value should be handled.

Options

  • Keep the original value (default)
  • Set the value to null
  • Go to the error route
note

Only available when Has Types? is enabled.

<?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>
go to error route

When Go to the error route is selected, messages with mismatches are sent to the Error Route and the following error is logged in the Flow Logs:

org.assimbly.util.exception.JsonTypeException:
There was a mismatch between a specified type and the value.
Type is 'number' and the value is 'John Johnson'.

Using XML to JSON Simple

XML attributes

XML attributes are converted into an object as key-value pairs. Each attribute's name becomes a key, prefixed with an @ (at) symbol to indicate it was originally an XML attribute. The value of the key is the attribute's original value. Additionally, the object includes the original XML node value in a key named jsonContent.

<?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>
Last update on Feb 25, 2025