Skip to main content
Version: 4.11.0

XML to JSON component

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

Configuration

It can be configured with the following options:

PropertyDescription
Force Top Level ObjectDetermines whether the resulting JSON will start off with a top-most element whose name matches the XML root element. If disabled, XML string <a><x>1</x><y>2</y></a> turns into { 'x: '1', 'y': '2' }. When enabled it turns into { 'a': { 'x: '1', 'y': '2' }}.
Skip whitespaceDetermines whether white spaces between XML elements will be interpreted as text values or will be ignored.
Trim spacesDetermines whether leading and trailing white spaces will be omitted from String values.
Skip namespacesSignals whether namespaces should be ignored. By default they will be added to the JSON output using @xmlns elements
Remove namespace prefixesRemoves the namespace prefixes from XML qualified elements, so that the resulting JSON string does not contain them.
Type HintsAdds type hints to the resulting XML to aid conversion back to JSON. Used for unmarshalling (JSON to XML conversion).

The default value for all of these properties is false.

Remarks

  • Empty XML tags, like <Reference_two/> or <Reference_two></Reference_two> will be converted to Json as empty arrays: "Reference_two":[]

Examples

1 - Using Type Hints in the input XML

Example input body:

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

Example output body:

{
"Drivers": [
{
"Name": "Max Verstappen",
"Age": 19
},
{
"Name": "Nico Hulkenberg",
"Age": 30
}
],
"Teams": [
{
"Name": "Redbull Racing",
"Principal": "Christian Horner"
},
{
"Name": "Renault",
"Principal": "Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul"
}
]
}