XML Converter

Convert an XML string to JSON or Pretty XML

Overview

This node converts an XML string into either a JSON object or a pretty-formatted XML string. It is useful when you need to transform XML data into a more accessible JSON format for further processing in workflows, or when you want to reformat XML with indentation and line breaks for readability.

Common scenarios include:

  • Parsing XML responses from APIs into JSON for easier manipulation.
  • Formatting raw XML data to a human-readable form.
  • Integrating systems that exchange data in XML by converting it to JSON.

Properties

Name Meaning
XML String The input XML string to be converted. Can be pasted directly or taken from previous nodes.
Output Format Choose the output format: JSON to convert XML to a JSON object, or Pretty XML to get a formatted XML string.

Output

The node outputs an array of items where each item contains a json field:

  • If Output Format is JSON, the json field contains the parsed XML as a JavaScript object.
  • If Output Format is Pretty XML, the json field contains an object with a single property xml holding the pretty-formatted XML string.

No binary data is output by this node.

Dependencies

  • Uses the xml2js library for parsing XML strings into JSON objects and building pretty XML strings.
  • No external API keys or services are required.
  • Requires no special environment variables or n8n credentials.

Troubleshooting

  • Invalid XML string error: This occurs if the provided XML string is empty or not a valid XML format. Ensure the input XML is well-formed.
  • Parsing errors: If the XML is malformed or contains unsupported constructs, the underlying parser will throw errors. Validate your XML before using the node.
  • Empty output: If the XML string is valid but results in an empty JSON object, verify the XML content actually contains data.

Links and References

Discussion