Skip to content

JSON to XML

This module converts JSON data to XML format using the fast-xml-parser library. It offers extensive configuration to control the XML output: root element name, indentation, XML declaration, attribute handling with custom prefixes, and CDATA fields. It can process the entire input or a specific field indicated by data_key. It is ideal for integrations with systems that require XML, such as SOAP services, electronic invoicing, or EDI data exchange.

ParameterTypeRequiredDescription
data_keytextNoPath to the JSON field to convert (e.g.: payload.order). Leave empty to use the entire input.
root_nametextNoName of the XML root tag. Default root.
declarationbooleanNoIf true, adds <?xml version="1.0" encoding="UTF-8"?> at the beginning. Default true.
indentselectNoXML indentation: 2 spaces, 4 spaces, tab or no indentation (compact). Default 2 spaces.
cdata_keystextNoFields that should be wrapped in CDATA, separated by comma (e.g.: description,body_html).
attribute_prefixtextNoPrefix to convert keys into XML attributes. Default _attr_. Example: _attr_id generates <tag id="...">.
output_keytextNoName of the field where to save the resulting XML. Leave empty to return {xml: '...', original: {...}}.
{
"nextModule": "siguiente_modulo",
"data": {
"xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<order>\n <id>123</id>\n <total>99.99</total>\n</order>",
"original": { "id": 123, "total": 99.99 }
},
"_meta_": {
"rootElement": "order",
"xmlLength": 95,
"hadCdata": false
}
}
{
"data_key": "payload",
"root_name": "invoice",
"declaration": true,
"indent": " ",
"cdata_keys": "description,notes",
"output_key": "xml_output"
}
  • Uses the fast-xml-parser library (XMLBuilder) for generation
  • CDATA fields are recursively wrapped in nested objects
  • Keys with the attribute prefix are converted to XML attributes of the parent element
  • If data_key is not found in the data, an error is returned
  • The _meta_ includes the root element name, XML length and whether CDATA was used
  • For the inverse operation (XML to JSON), use the xmlToJson module
  • xmlToJson (inverse operation: XML to JSON)
  • jsonToToon (conversion to TOON format)
  • dataset (prepare data before converting to XML)