Skip to content

XML to JSON

This module converts XML data to JSON format using the fast-xml-parser library. It offers advanced configuration to control parsing: XML attribute handling with custom prefixes, text nodes, whitespace trimming, automatic number and boolean parsing, root element removal, and definition of tags that should always be arrays. It looks for the XML string in the input in various ways: through a specific field, as a direct string, or in common fields like xml, body or payload. It is ideal for processing SOAP service responses, electronic invoicing files or EDI data.

ParameterTypeRequiredDescription
data_keytextNoPath to the field containing the XML string (e.g.: payload.body). Leave empty if the complete input is XML.
ignore_attributesbooleanNoIf true, omits XML tag attributes. Default false.
attribute_prefixtextNoPrefix for attribute names in the resulting JSON. Default _attr_.
text_node_nametextNoKey name for text content when a tag has attributes and children. Default #text.
trim_valuesbooleanNoRemoves leading and trailing whitespace from values. Default true.
parse_numbersbooleanNoAutomatically converts numeric values ("123" to 123). Default true.
parse_booleansbooleanNoConverts "true"/"false" to booleans. Default true.
remove_rootbooleanNoExtracts the content of the first root tag, removing the wrapper. Default false.
array_tagstextNoTags that should always be arrays even if they have a single child, separated by comma (e.g.: item,line_item).
output_keytextNoName of the field where to save the resulting JSON. Leave empty to return directly.
{
"nextModule": "siguiente_modulo",
"data": {
"order": {
"id": 123,
"items": [
{ "name": "Producto A", "quantity": 2 }
]
}
},
"_meta_": {
"xmlLength": 250,
"elementCount": 8,
"rootRemoved": false,
"attributesIgnored": false
}
}
{
"data_key": "payload.xml_response",
"remove_root": true,
"array_tags": "item,line_item",
"parse_numbers": true,
"parse_booleans": true
}
  • Uses the fast-xml-parser library (XMLParser) for parsing
  • Looks for the XML string in this order: data_key > direct input as string > data.xml > data.body > data.payload
  • The input must start with < to be recognized as valid XML
  • Tags defined in array_tags are always converted to arrays even if they have a single child
  • Boolean conversion is applied recursively throughout the structure
  • The _meta_ includes original XML length, element count and configuration flags
  • jsonToXml (inverse operation: JSON to XML)
  • toonToJson (conversion from TOON format)
  • dataTransform (transform the resulting JSON)