JSON to XML component
The JSON to XML component allows you to convert JSON formatted input into XML output directly.
Configuration
The JSON to XML component has the following configuration options:
Element Name
Specify XML node name for array elements. The default value is element
.
See the example below with default settings:
- JSON Input
- XML Output - Default
- XML Output - order
[
1,
2,
3
]
<?xml version="1.0" encoding="UTF-8"?>
<array>
<element>1</element>
<element>2</element>
<element>3</element>
</array>
<?xml version="1.0" encoding="UTF-8"?>
<array>
<order>1</order>
<order>2</order>
<order>3</order>
</array>
Array Name
Specify the name of the top-level XML element if the JSON starts with an array. The default value is array
.
See the example below with default settings:
- JSON Input
- XML Output - Default
- XML Output - list
[
1,
2,
3
]
<?xml version="1.0" encoding="UTF-8"?>
<array>
<element>1</element>
<element>2</element>
<element>3</element>
</array>
<?xml version="1.0" encoding="UTF-8"?>
<list>
<element>1</element>
<element>2</element>
<element>3</element>
</list>
If a Root Name is specified, the root node will be renamed accordingly. For example <array>
becomes <root>
.
Root Name
Specify the name of the top-level element. The default value is empty, but it will fallback to o
if the JSON does not start with an array.
See the two examples below:
- JSON Input
- XML Output - Empty
- XML Output - root
{
"x": "value1",
"y": "value2"
}
<?xml version="1.0" encoding="UTF-8"?>
<o>
<x>value1</x>
<y>value2</y>
</o>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<x>value1</x>
<y>value2</y>
</root>
If the JSON starts with an array and Root Name is empty, the root element will use the value specified in Array Name.
- JSON Input
- XML Output - Empty
- XML Output - root
[
1,
2,
3
]
<?xml version="1.0" encoding="UTF-8"?>
<array>
<element>1</element>
<element>2</element>
<element>3</element>
</array>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<element>1</element>
<element>2</element>
<element>3</element>
</root>
Namespace lenient
Specify whether to tolerate incomplete namespace prefixes.
Options
Yes
No
(default)
Type Hints
Specify whether to add type hints to the XML output.
Options
Yes
No
(default)
Using JSON to XML
Simple example
See the example below with the following settings (unmentioned settings use default values):
- Element Name :
orderline
- Array Name :
order
- Root Name :
orders
- JSON Input
- XML Output
{
"order_numbers": [
"201406",
"201407",
"201408"
]
}
<?xml version="1.0" encoding="UTF-8"?>
<orders>
<order_numbers>
<orderline>201406</orderline>
<orderline>201407</orderline>
<orderline>201408</orderline>
</order_numbers>
</orders>
Type hint example
See the example below with the following settings (unmentioned settings use default values):
- Element Name :
Element
- Array Name :
Array
- Root Name :
Formula1
- Type Hints :
Yes
- JSON Input
- XML Output
{
"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"
}
]
}
<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers class="array">
<Element class="object">
<Name type="string">Max Verstappen</Name>
<Age type="number">19</Age>
</Element>
<Element class="object">
<Name type="string">Nico Hulkenberg</Name>
<Age type="number">30</Age>
</Element>
</Drivers>
<Teams class="array">
<Element class="object">
<Name type="string">Redbull Racing</Name>
<Principal type="string">Christian Horner</Principal>
</Element>
<Element class="object">
<Name type="string">Renault</Name>
<Principal type="string">Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
</Element>
</Teams>
</Formula1>