JSON to XML Simple component
The JSON to XML Simple component provides a direct conversion from the JSON format to the XML format.
Configuration
It has the following configuration options:
- Add a root tag?
- Specify root tag name
-
When a JSON key contains invalid XML characters
-
Change the name of array elements?
-
Specify the custom array element name
Keep in mind that each enabled option could take some extra time to complete the transformation.
Add a root tag?
Options
yes
no
(default)
Description
By default the component won't add a root tag around the resulting XML. By selecting
yes
a root tag will be added that wraps the resulting XML. By default it will
be called root
, but you can rename it in the
Specify root tag name option.
Example
- Source JSON
- XML - 'no' is selected
- XML - 'yes' is selected
{
"Formula1": {
"Drivers": {
"Driver": [
{
"Age": 19,
"Name": "Max Verstappen"
},
{
"Age": 30,
"Name": "Nico Hulkenberg"
}
]
},
"Teams": {
"Team": [
{
"Principal": "Christian Horner",
"Name": "Redbull Racing"
},
{
"Principal": "Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul",
"Name": "Renault"
}
]
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers>
<Driver>
<Age>19</Age>
<Name>Max Verstappen</Name>
</Driver>
<Driver>
<Age>30</Age>
<Name>Nico Hulkenberg</Name>
</Driver>
</Drivers>
<Teams>
<Team>
<Principal>Christian Horner</Principal>
<Name>Redbull Racing</Name>
</Team>
<Team>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
<Name>Renault</Name>
</Team>
</Teams>
</Formula1>
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Formula1>
<Drivers>
<Driver>
<Age>19</Age>
<Name>Max Verstappen</Name>
</Driver>
<Driver>
<Age>30</Age>
<Name>Nico Hulkenberg</Name>
</Driver>
</Drivers>
<Teams>
<Team>
<Principal>Christian Horner</Principal>
<Name>Redbull Racing</Name>
</Team>
<Team>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
<Name>Renault</Name>
</Team>
</Teams>
</Formula1>
</root>
Specify root tag name
Description
This option allows you to specify a custom root tag. By default it will be root
.
Remarks
- This field only becomes visible when you want to add a root tag to the resulting XML.
- Simple headers can be specified to create a dynamic root tag.
- Example:
${header.headerName}
- Example:
- Since it will be used in an XML element the following rules apply:
- Names can't start with a digit
- Names can't start with special characters like hypens or periods
- Names can't start with any variation of 'xml'
- Names can't contain special characters other than the period, hyphen, underscore, and colon
When a JSON key contains invalid XML characters
Options
filter these characters
don't filter these characters and go to the error route
(default)
Description
By default the component won't filter invalid XML characters from the JSON keys. This
could lead to errors which will direct the exchange to the error route. If you're
not sure if the JSON could contain invalid XML characters in the JSON keys you
can select filter these characters
.
The following rules apply for the filter:
- Names can't start with a digit
- Names can't start with special characters like hypens or periods
- Names can't start with any variation of 'xml'
- Names can't contain special characters other than the period, hyphen, underscore, and colon
Some JSON keys that could never be valid as an XML element on their own
are prepended with element-
.
Example
Notice that the JSON key "123"
becomes the XML element element-123
.
- Source JSON
- XML - 'filter these characters' is selected
{
"Formula1": {
"Drivers": {
"Driver": [
{
"A!ge": 19,
"Na>me": "Max Verstappen"
},
{
"Ag?e": 30,
"Nam<>e": "Nico Hulkenberg"
}
]
},
"Tea#@ms": {
"!Tea!m": [
{
"!@!Principal": "Christian Horner",
"12Name!": "Redbull Racing"
},
{
"45Principa!l": "Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul",
"xmlName": "Renault"
}
]
},
"123": "example"
}
}
<?xml version="1.0" encoding="UTF-8"?>
<root>
<Formula1>
<element->another example</element->
<Drivers>
<Driver>
<Age>19</Age>
<Name>Max Verstappen</Name>
</Driver>
<Driver>
<Age>30</Age>
<Name>Nico Hulkenberg</Name>
</Driver>
</Drivers>
<element-123>example</element-123>
<Teams>
<Team>
<Principal>Christian Horner</Principal>
<Name>Redbull Racing</Name>
</Team>
<Team>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
<Name>Renault</Name>
</Team>
</Teams>
</Formula1>
</root>
Change the name of array elements?
Options
yes
no
(default)
Description
By default the component will use the name of the JSON key of the an array to
name the nodes in the resulting XML. To change this behaviour you can select yes
and specify the name you want to use in the option:
Specify the custom array element name.
Examples
- Source JSON
- XML - 'no' is selected
- XML - 'yes' is selected
{
"Formula1": {
"Drivers": {
"Driver": [
{
"Age": 19,
"Name": "Max Verstappen"
},
{
"Age": 30,
"Name": "Nico Hulkenberg"
}
]
},
"Teams": {
"Team": [
{
"Principal": "Christian Horner",
"Name": "Redbull Racing"
},
{
"Principal": "Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul",
"Name": "Renault"
}
]
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers>
<Driver>
<Age>19</Age>
<Name>Max Verstappen</Name>
</Driver>
<Driver>
<Age>30</Age>
<Name>Nico Hulkenberg</Name>
</Driver>
</Drivers>
<Teams>
<Team>
<Principal>Christian Horner</Principal>
<Name>Redbull Racing</Name>
</Team>
<Team>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
<Name>Renault</Name>
</Team>
</Teams>
</Formula1>
<?xml version="1.0" encoding="UTF-8"?>
<Formula1>
<Drivers>
<element>
<Age>19</Age>
<Name>Max Verstappen</Name>
</element>
<element>
<Age>30</Age>
<Name>Nico Hulkenberg</Name>
</element>
</Drivers>
<Teams>
<element>
<Principal>Christian Horner</Principal>
<Name>Redbull Racing</Name>
</element>
<element>
<Principal>Carlos Ghosn, Jérôme Stoll, Cyril Abiteboul</Principal>
<Name>Renault</Name>
</element>
</Teams>
</For
Specify the custom array element name
Description
This option allows you to specify a name for array elements. By default it will
be element
.
Remarks
- This field only becomes visible when you want to specify a custom array element name.
- Simple headers can be specified to create a dynamic array element name.
- Example:
${header.headerName}
- Example:
- Since it will be used in an XML element the following rules apply:
- Names can't start with a digit.
- Names can't start with special characters like hypens or periods.
- Names can't start with any variation of 'xml'.
- Names can't contain special characters other than the period, hyphen, underscore, and colon.
Remarks
JSON with root array
When the JSON starts with an array like this:
[
{
"key": "value"
}
]
You need to set Add a root tag? to yes
. Otherwise
invalid XML will be generated that will result in an exception.