JSON to XML
Description
Section titled “Description”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.
Configuration
Section titled “Configuration”Parameters
Section titled “Parameters”| Parameter | Type | Required | Description |
|---|---|---|---|
| data_key | text | No | Path to the JSON field to convert (e.g.: payload.order). Leave empty to use the entire input. |
| root_name | text | No | Name of the XML root tag. Default root. |
| declaration | boolean | No | If true, adds <?xml version="1.0" encoding="UTF-8"?> at the beginning. Default true. |
| indent | select | No | XML indentation: 2 spaces, 4 spaces, tab or no indentation (compact). Default 2 spaces. |
| cdata_keys | text | No | Fields that should be wrapped in CDATA, separated by comma (e.g.: description,body_html). |
| attribute_prefix | text | No | Prefix to convert keys into XML attributes. Default _attr_. Example: _attr_id generates <tag id="...">. |
| output_key | text | No | Name of the field where to save the resulting XML. Leave empty to return {xml: '...', original: {...}}. |
Output
Section titled “Output”{ "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 }}Usage Example
Section titled “Usage Example”Basic case
Section titled “Basic case”{ "data_key": "payload", "root_name": "invoice", "declaration": true, "indent": " ", "cdata_keys": "description,notes", "output_key": "xml_output"}- Uses the
fast-xml-parserlibrary (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_keyis 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
Related Nodes
Section titled “Related Nodes”- xmlToJson (inverse operation: XML to JSON)
- jsonToToon (conversion to TOON format)
- dataset (prepare data before converting to XML)