XML to JSON component
The XML to JSON component allows you to convert XML files into JSON files.
Configuration
The XML to JSON component has the following basic configuration options:
Force Top Level Object
Specify whether the resulting JSON will start off with a top-most element whose name matches the XML root element.
Options
Yes
No
(default)
- XML Input
- JSON Output - No
- JSON Output - Yes
<?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>
{
"root": {
"person": [
{
"name": "John Johnson",
"age": 19
},
{
"name": "John Foo",
"age": 30
},
{
"name": "John Doe",
"age": 30
}
]
}
}
{
"person": [
{
"name": "John Johnson",
"age": 19
},
{
"name": "John Foo",
"age": 30
},
{
"name": "John Doe",
"age": 30
}
]
}
Skip whitespace
Specify whether white spaces between XML elements will be interpreted as text values or will be ignored.
Options
Yes
No
(default)
Trim spaces
Specify whether leading and trailing white spaces will be omitted from string
values.
Options
Yes
No
(default)
- XML Input
- JSON Output - No
- JSON Output - Yes
<?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>
[
{
"name": " John Johnson ",
"age": "19"
},
{
"name": "John Foo",
"age": "30"
},
{
"name": "John Doe",
"age": "30"
}
]
[
{
"name": "John Johnson",
"age": "19"
},
{
"name": "John Foo",
"age": "30"
},
{
"name": "John Doe",
"age": "30"
}
]
Skip namespaces
Specify whether to remove namespaces from the JSON output. By default they will be added to the JSON output using @xmlns
.
Options
Yes
No
(default)
- XML Input
- JSON Output - No
- JSON Output - Yes
<?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>
{
"h:table": {
"@xmlns:h": "http://www.dovetail.world/TR/html4/",
"h:tr": {
"h:td": [
"Apples",
"Bananas"
]
}
},
"f:table": {
"@xmlns:f": "https://www.dovetail.world/furniture",
"f:name": "African Coffee Table",
"f:width": "80",
"f:length": "120"
}
}
{
"h:table": {
"h:tr": {
"h:td": [
"Apples",
"Bananas"
]
}
},
"f:table": {
"f:name": "African Coffee Table",
"f:width": "80",
"f:length": "120"
}
}
Remove namespace prefixes
Specify whether to remove namespace prefixes from XML node names.
Options
Yes
No
(default)
- XML Input
- JSON Output - No
- JSON Output - Yes
<?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>
{
"h:table": {
"@xmlns:h": "http://www.dovetail.world/TR/html4/",
"h:tr": {
"h:td": [
"Apples",
"Bananas"
]
}
},
"f:table": {
"@xmlns:f": "https://www.dovetail.world/furniture",
"f:name": "African Coffee Table",
"f:width": "80",
"f:length": "120"
}
}
{
"table": {
"@xmlns:f": "https://www.dovetail.world/furniture",
"name": "African Coffee Table",
"width": "80",
"length": "120"
}
}
Type Hints
Adds type hints to the resulting XML to aid conversion back to JSON. Used for unmarshalling (JSON to XML conversion)
Options
False
(default)True
- XML Input
- JSON Output - False
- JSON Output - True
<?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>
{
"Drivers": {
"@class": "array",
"Driver": [
{
"@class": "object",
"Name": {
"@type": "string",
"#text": "Max Verstappen"
},
"Age": {
"@type": "number",
"#text": "19"
}
},
{
"@class": "object",
"Name": {
"@type": "string",
"#text": "Nico Hulkenberg"
},
"Age": {
"@type": "number",
"#text": "30"
}
}
]
},
"Teams": {
"@class": "array",
"Team": [
{
"@class": "object",
"Name": {
"@type": "String",
"#text": "Redbull Racing"
},
"Principal": {
"@type": "string",
"#text": "Christian Horner"
}
},
{
"@class": "object",
"Name": {
"@type": "String",
"#text": "Renault"
},
"Principal": {
"@type": "string",
"#text": "Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul"
}
}
]
}
}
{
"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"
}
]
}
Using XML to JSON
Empty XML nodes
Empty XML nodes, like <Reference_two/>
or <Reference_two></Reference_two>
will be converted into empty JSON arrays: "Reference_two" : []
.