# XML to JSON Transformer

**XML to JSON Transformer** transforms an XML string into a JSON object.

## Parameters

Configure the connector using the parameters below. Fields that support [Double Braces expressions](https://docs.digibee.com/documentation/connectors-and-triggers/double-braces) are marked in the **Supports DB** column.

{% tabs fullWidth="true" %}
{% tab title="General" %}

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Type</th><th>Supports DB</th><th>Default</th></tr></thead><tbody><tr><td><strong>Alias</strong></td><td>Name (alias) for this connector’s output, allowing you to <a href="../../double-braces/how-to-reference-data-using-double-braces">reference it later in the flow using Double Braces expressions</a></td><td>String</td><td>✅</td><td>xml-to-json-1</td></tr><tr><td><strong>XML Field Path</strong></td><td>Path of the XML field to be transformed, using dotted notation. If the field is a matrix, all elements will be processed. You can specify multiple fields separated by commas.</td><td>String</td><td>❌</td><td>body</td></tr><tr><td><strong>Preserve Original</strong></td><td>IIf enabled, the original fields are preserved in the transformation result. To differentiate the original fields from the transformed ones, an underscore (<code>_</code>) is added at the beginning of the original field names.</td><td>Boolean</td><td>❌</td><td>True</td></tr><tr><td><strong>With Namespace</strong></td><td>If enabled, the XML namespaces are preserved in the transformation result.</td><td>Boolean</td><td>❌</td><td>True</td></tr><tr><td><strong>Remove XML Attributes</strong></td><td>If enabled, the XML attributes are hidden in the transformation result.</td><td>Boolean</td><td>❌</td><td>False</td></tr><tr><td><strong>All Values As String</strong></td><td>If enabled, all XML tag values are converted to the string type.</td><td>Boolean</td><td>❌</td><td>False</td></tr><tr><td><strong>Escape Special Characters</strong></td><td>If enabled, automatically escapes reserved XML characters ( <code>&#x26;</code>, <code>&#x3C;</code>, <code>></code>) to prevent parsing errors during data transformation.</td><td>Boolean</td><td>❌</td><td>False</td></tr></tbody></table>
{% endtab %}

{% tab title="Documentation" %}

<table data-full-width="true"><thead><tr><th>Parameter</th><th>Description</th><th>Type</th><th>Supports DB</th><th>Default</th></tr></thead><tbody><tr><td><strong>Documentation</strong></td><td>Optional field to describe the connector configuration and any relevant business rules.</td><td>String</td><td>❌</td><td>N/A</td></tr></tbody></table>
{% endtab %}
{% endtabs %}

## Messages flow <a href="#h_2ed0ed2b2e" id="h_2ed0ed2b2e"></a>

### Input <a href="#h_f59d577ce4" id="h_f59d577ce4"></a>

The connector doesn’t require a specific input message. You only need to configure the **XML Field Path** parameter with a reference to the field path that contains the XML to be transformed. This field must be present in the output of the step immediately before the **XML to JSON Transformer** execution.

### Output <a href="#h_cb4324f50b" id="h_cb4324f50b"></a>

The output structure remains the same as the one received in the previous step. The fields specified in the **XML Field Path** parameter are transformed into their JSON object representation. If an error occurs, an error property is created at the same level as the original property.

When the **Preserve Origina**l parameter is enabled, each field defined in the **XML Field Path** parameter generates an additional property prefixed with an underscore (\_), containing the original XML string.

The JSON dotted notation identifies the root element being processed by the pipeline and navigates through it according to the path defined in the **XML Field Path** parameter.

**Example:**

In an X**ML Field Path** represented as `a.b.c.d`, the connector will:

1. Look for the element `a` at the root level.
2. Inside `a` it will find `b`.
3. Then, inside `b` it will find `c`.
4. Finally, it will access `d`, which is the element to be transformed.

The connector identifies each `<d>` element inside `<c> → <b> → <a>` and converts them into JSON.

If an **array** is found along the path (for example, if `b` contains multiple items), the algorithm processes **each array element individually**, creating a separate path for each one.

In other words, the algorithm replaces **all occurrences** of the path defined in the **XML Field Path** parameter throughout the message.&#x20;

## XML to JSON Transformer in action <a href="#h_33bc3ca091" id="h_33bc3ca091"></a>

For all the scenarios below, the following payload will be considered with the XML String field:&#x20;

```json
{
  "xmlField": "<?xml version=\"1.0\" ?><inf:ProductInformation xmlns:inf=\"urn:product:Info\" xmlns:stk=\"urn:product:Stock\"><inf:ProductName Code=\"C00001\">Computer</inf:ProductName><inf:Price Units=\"$\">2500</inf:Price><stk:Volume Units=\"Units\">200</stk:Volume></inf:ProductInformation>"
}
```

### XML Transformation <a href="#h_586bab2c1e" id="h_586bab2c1e"></a>

#### **Input**

**Parameters**

* **XML Field Path:** `xmlField`
* **Preserve Original**: false
* **With Namespace**: false
* **Remove XML Attributes**: false
* **All Values As String**: false

#### **Output**

```json
{
  "xmlField": {
    "ProductInformation": {
      "ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "Price": {
        "Units": "$",
        "content": 2500
      },
      "Volume": {
        "Units": "Units",
        "content": 200
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info"
    }
  }
}
```

### XML Transformation with the "Preserve Original" parameter enabled <a href="#h_5aa3fbd84f" id="h_5aa3fbd84f"></a>

#### **Input**

**Parameters**

* **XML Field Path:** `xmlField`
* **Preserve Original**: true
* **With Namespace**: false
* **Remove XML Attributes**: false
* **All Values As String**: false

#### **Output**

```json
{
  "xmlField": {
    "ProductInformation": {
      "ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "Price": {
        "Units": "$",
        "content": 2500
      },
      "Volume": {
        "Units": "Units",
        "content": 200
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info"
    }
  },
  "_xmlField": "<?xml version=\"1.0\" ?><inf:ProductInformation xmlns:inf=\"urn:product:Info\" xmlns:stk=\"urn:product:Stock\"><inf:ProductName Code=\"C00001\">Computer</inf:ProductName><inf:Price Units=\"$\">2500</inf:Price><stk:Volume Units=\"Units\">200</stk:Volume></inf:ProductInformation>"
}
```

### XML Transformation with the "With Namespace" parameter enabled <a href="#h_7278e79bbd" id="h_7278e79bbd"></a>

#### **Input**

**Parameters**

* **XML Field Path:** `xmlField`
* **Preserve Original**: false
* **With Namespace**: true
* **Remove XML Attributes**: false
* **All Values As String**: false

#### **Output**

```json
{
  "xmlField": {
    "inf:ProductInformation": {
      "inf:Price": {
        "Units": "$",
        "content": 2500
      },
      "xmlns:stk": "urn:product:Stock",
      "xmlns:inf": "urn:product:Info",
      "inf:ProductName": {
        "Code": "C00001",
        "content": "Computer"
      },
      "stk:Volume": {
        "Units": "Units",
        "content": 200
      }
    }
  }
}
```

### XML Transformation with the "Remove XML Attributes" parameter enabled <a href="#h_a2839d8e49" id="h_a2839d8e49"></a>

#### **Input**

**Parameters**

* **XML Field Path:** `xmlField`
* **Preserve Original**: false
* **With Namespace**: false
* **Remove XML Attributes**: true
* **All Values As String**: false

#### **Output**

```json
{
  "xmlField": {
    "ProductInformation": {
      "ProductName": "Computer",
      "Price": 2500,
      "Volume": 200
    }
  }
}
```

### XML Transformation with the "All Values As String" parameter enabled <a href="#h_0011df99d0" id="h_0011df99d0"></a>

#### **Input**

**Parameters**

* **XML Field Path:** `xmlField`
* **Preserve Original**: false
* **With Namespace**: false
* **Remove XML Attributes**: false
* **All Values As String**: true

#### **Output**

```json
{
  "xmlField": {
    "ProductInformation": {
      "ProductName": "Computer",
      "Price": "2500",
      "Volume": "200"
    }
  }
}
```

### XML Transformation with the with “Escape Special Characters” parameter enabled

#### Input

```json
{
  "xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<sales_report>\n  <company>Solutions &amp; Co. Ltd.</company>\n  <generation_date>2025-10-13</generation_date>\n  \n  <product id=\"A101\">\n    <name>TurboX Graphics Card</name>\n    <stock>50</stock>\n    <rating>4.5</rating>\n    <comparison>Performance &gt; Price</comparison>\n  </product>\n  \n  <product id=\"B202\">\n    <name>Velox 9 Processor</name>\n    <stock>35</stock>\n    <rating>4.8</rating>\n    <comparison>Cost &lt; Benefit</comparison>\n  </product>\n  \n  <notes>\n    Review order #PO-789 &amp; #PO-790.\n    The sales goal is &gt; 100 units for the Velox 9 Processor.\n    The cost must be &lt; $500 per unit.\n  </notes>\n  \n</sales_report>"
}

```

* **XML Field Path:** `xmlField`
* **Preserve Original**: false
* **With Namespace**: false
* **Remove XML Attributes**: false
* **All Values As String**: false
* **Escape Special Characters:** true

```json
{
  "xml": {
    "sales_report": {
      "notes": "    Review order #PO-789 & #PO-790.\n    The sales goal is > 100 units for the Velox 9 Processor.\n    The cost must be < $500 per unit.\n ",
      "product": [
        {
          "stock": 50,
          "comparison": "Performance > Price",
          "name": "TurboX Graphics Card",
          "id": "A101",
          "rating": 4.5,
          "content": [
            "   ",
            "   ",
            "   ",
            "   ",
            " "
          ]
        },
        {
          "stock": 35,
          "comparison": "Cost < Benefit",
          "name": "Velox 9 Processor",
          "id": "B202",
          "rating": 4.8,
          "content": [
            "   ",
            "   ",
            "   ",
            "   ",
            " "
          ]
        }
      ],
      "company": "Solutions & Co. Ltd.",
      "content": [
        " ",
        " ",
        "  \n ",
        "  \n ",
        "  \n ",
        "  "
      ],
      "generation_date": "2025-10-13"
    }
  }
}

```
