Reference · Tools

XML

Convert between XML and JSON formats.

Action Core Nodes v1

The XML node converts between XML strings and JSON objects in both directions, with configurable parser and builder options. It needs no credentials. A typical build is turning a legacy SOAP or XML API response into JSON the rest of the workflow can work with.

Node type
Action
Parameters
4
Outputs
Output, Error
Credentials
None required

XML

Convert between XML and JSON

Overview

The XML tool converts data between XML and JSON. In xmlToJson mode, it parses an XML string from an item field into a JSON object. In jsonToXml mode, it builds an XML string from a JSON object. Uses the xml2js library with configurable options for attribute handling, arrays, root elements, and more.

Category: Core Nodes
Tool Name: xml
Version: 1

Appearance: Icon: lucide-FileCode | Color: #333399

Node Type

Action — processes input items and produces output

Input / Output

DirectionPort(s)
InputInput
OutputOutput, Error

Credentials

This tool does not require any credentials.

Parameters

ParameterTypeRequiredDefaultDescription
ModeoptionsNoxmlToJsonConversion direction.
Options: jsonToXml, xmlToJson
Property NamestringYesdataThe name of the property containing the data to convert. The converted value is written back to this same property.
OptionscollectionNo{}Parser and builder settings; which ones apply depends on Mode.
— Attribute KeystringNo$Prefix for XML attribute keys in the JSON output.
— Character KeystringNo_Key for character content in mixed-content elements.
— Explicit ArraybooleanNofalseAlways put child nodes in an array (even single elements). (shown when Mode is xmlToJson)
— Explicit RootbooleanNotrueWhether to include the root element in the JSON output. (shown when Mode is xmlToJson)
— Ignore AttributesbooleanNofalseIgnore all XML attributes. (shown when Mode is xmlToJson)
— Merge AttributesbooleanNotrueMerge attributes and child elements as properties of the parent. (shown when Mode is xmlToJson)
— NormalizebooleanNofalseTrim whitespace inside text nodes. (shown when Mode is xmlToJson)
— Normalize TagsbooleanNofalseNormalize all tag names to lowercase. (shown when Mode is xmlToJson)
— TrimbooleanNofalseTrim leading/trailing whitespace from text nodes. (shown when Mode is xmlToJson)
— Allow Surrogate CharsbooleanNofalseAllow surrogate character pairs in XML output. (shown when Mode is jsonToXml)
— CDATAbooleanNofalseWrap text nodes in CDATA sections. (shown when Mode is jsonToXml)
— HeadlessbooleanNofalseOmit the XML declaration header. (shown when Mode is jsonToXml)
— Root NamestringNoRoot element name (if input JSON has no root element). (shown when Mode is jsonToXml)
Max ConcurrencynumberNo10Maximum number of items to process concurrently.

Output Data

One output item per input item. The conversion happens in place: the property named by Property Name is overwritten with the converted value. Every other field in the item JSON passes through unchanged, and binary data is forwarded.

  • xmlToJson — the property must hold an XML string, or the item fails with Property "<name>" does not contain a string value. It is replaced by the parsed object. Attribute Key and Character Key control where attributes and mixed text end up; note that Merge Attributes is on by default, so attributes appear as ordinary properties of their element rather than nested under the attribute key.
  • jsonToXml — the property is replaced by the generated XML string. An object is serialized directly; a string value is parsed as JSON first, so a stringified payload works too. Root Name supplies the wrapping element when the object does not already have a single root.

Reference the result downstream by expression, e.g. {{ $json.data }}.

Usage Examples

  • Parse XML API response into JSON
  • Build XML payload from JSON data
  • Convert XML string field to navigable JSON object

Example Configuration

Basic XML to JSON conversion:

{
  "type": "xml",
  "parameters": {
    "mode": "xmlToJson",
    "dataPropertyName": "xmlData"
  }
}

XML to JSON with custom options:

{
  "type": "xml",
  "parameters": {
    "mode": "xmlToJson",
    "dataPropertyName": "xmlContent",
    "maxConcurrency": 5,
    "options": {
      "attrkey": "attributes",
      "charkey": "text",
      "explicitArray": true,
      "ignoreAttrs": false,
      "trim": true,
      "normalize": true
    }
  }
}

JSON to XML conversion:

{
  "type": "xml",
  "parameters": {
    "mode": "jsonToXml",
    "dataPropertyName": "jsonData",
    "options": {
      "rootName": "document",
      "attrkey": "$",
      "charkey": "_",
      "headless": false,
      "cdata": true
    }
  }
}

High-concurrency parsing with a flattened result:

{
  "type": "xml",
  "parameters": {
    "mode": "xmlToJson",
    "dataPropertyName": "batchData",
    "maxConcurrency": 20,
    "options": {
      "explicitRoot": false,
      "mergeAttrs": true,
      "normalizeTags": true,
      "trim": true
    }
  }
}

Convert a fetched RSS/XML feed to JSON:

{
  "type": "xml",
  "parameters": {
    "mode": "xmlToJson",
    "dataPropertyName": "feedXml",
    "options": {
      "attrkey": "attr",
      "charkey": "content",
      "explicitArray": false,
      "trim": true,
      "normalize": true,
      "ignoreAttrs": false
    }
  }
}

Generate clean XML from structured JSON:

{
  "type": "xml",
  "parameters": {
    "mode": "jsonToXml",
    "dataPropertyName": "structuredData",
    "options": {
      "rootName": "root",
      "headless": false,
      "allowSurrogateChars": false,
      "attrkey": "@",
      "charkey": "#text"
    }
  }
}

Parse a configuration file:

{
  "type": "xml",
  "parameters": {
    "mode": "xmlToJson",
    "dataPropertyName": "configXml",
    "options": {
      "explicitRoot": true,
      "mergeAttrs": true,
      "trim": true,
      "normalizeTags": false,
      "explicitArray": false
    }
  }
}

Error Handling

ModeBehavior
stopHalts workflow on first error
continueSkips failed items, passes successful ones through
errorPortRoutes failed items to Error output port

Tips

Converts between XML strings and JSON objects using xml2js with configurable parser/builder options.

Behavior notes

  • Explicit Array changes the shape of everything downstream. Left off, a single <item> becomes an object and two become an array, so expressions that work on one feed break on another. Turn it on when the feed’s cardinality varies and always index ({{ $json.data.rss.channel[0].item }}).
  • Attribute Key and Character Key apply in both directions. Whatever you choose when parsing is what you must use when building XML back out of the same structure.
  • The source property is overwritten. If you need the original XML as well, copy it to another field before this node.

Frequently asked questions

Why do my expressions break on some responses but not others?

Explicit Array changes the shape of everything downstream. Left off, a single `<item>` becomes an object and two become an array, so an expression written against one response breaks on another.

When should I turn Explicit Array on?

When the feed's cardinality varies. With it on, everything is consistently an array, so always index — for example `{{ $json.data.rss.channel[0] }}` — and your expressions stay stable.

Can it produce XML as well as parse it?

Yes, conversion runs in both directions, so you can build an XML payload for an API that requires one.

Does it need credentials?

No — it is a local conversion.

Build with the XML node

Drop it into a workflow, wire it to an agent, or call it on a schedule.

Open BusyBot

Last updated . Spotted something wrong? Tell us.