XML to JSON
Description
Section titled “Description”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.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| data_key | text | No | Path to the field containing the XML string (e.g.: payload.body). Leave empty if the complete input is XML. |
| ignore_attributes | boolean | No | If true, omits XML tag attributes. Default false. |
| attribute_prefix | text | No | Prefix for attribute names in the resulting JSON. Default _attr_. |
| text_node_name | text | No | Key name for text content when a tag has attributes and children. Default #text. |
| trim_values | boolean | No | Removes leading and trailing whitespace from values. Default true. |
| parse_numbers | boolean | No | Automatically converts numeric values ("123" to 123). Default true. |
| parse_booleans | boolean | No | Converts "true"/"false" to booleans. Default true. |
| remove_root | boolean | No | Extracts the content of the first root tag, removing the wrapper. Default false. |
| array_tags | text | No | Tags that should always be arrays even if they have a single child, separated by comma (e.g.: item,line_item). |
| output_key | text | No | Name of the field where to save the resulting JSON. Leave empty to return directly. |
Output
Section titled “Output”{ "nextModule": "siguiente_modulo", "data": { "order": { "id": 123, "items": [ { "name": "Producto A", "quantity": 2 } ] } }, "_meta_": { "xmlLength": 250, "elementCount": 8, "rootRemoved": false, "attributesIgnored": false }}Usage Example
Section titled “Usage Example”Basic case
Section titled “Basic case”{ "data_key": "payload.xml_response", "remove_root": true, "array_tags": "item,line_item", "parse_numbers": true, "parse_booleans": true}- Uses the
fast-xml-parserlibrary (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_tagsare 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
Related Nodes
Section titled “Related Nodes”- jsonToXml (inverse operation: JSON to XML)
- toonToJson (conversion from TOON format)
- dataTransform (transform the resulting JSON)