All Collections
Components
XML to JSON Transformer
XML to JSON Transformer

Know the component and how to use it.

Erick Rubiales avatar
Written by Erick Rubiales
Updated over a week ago

IMPORTANT: This documentation has been discontinued. Read the updated XML to JSON Transformer documentation on our new documentation portal.

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

Take a look at the configuration parameters of the component:

  • XML Field Path: field path of the XML string to be transformed. This path representation must be made in dotted notation. If the field is a matrix, all the elements of this matrix will be run. You can specify multiple fields, separating them by comma.

  • Preserve Original: if the option is enabled, the original fields are preserved in the transformation result and, to differ the name of the transformed fields, the “_” character will be added in the beginning of the name of the original fields.

  • With Namespace: if the option is enabled, the XML namespaces will be kept in the transformation result. 

  • Remove XML Attributes: if the option is enabled, the XML attributes will be hidden in the transformation result.

  • All Values As String: if the option is enabled, all the XML tag values will be transformed to string type.

 

Messages flow

Input

The component doesn’t expect a specific input message, just the XML Field Path configuration parameter to be filled with a reference to the path of the field to be transformed. This field must exist in the message of the step prior to the XML to JSON Transformer execution.

Output

The structure will be the same as the one received in the previous step of the flow, but the fields informed in the XML Field Path parameter will be transformed in the JSON object representation. In case of error, the “error” property will be created at the same level of the original property.

When the Preserve Original parameter is enabled, for each field informed in the XML Field Path parameter, a new property will be informed just by adding the “_” character in the beginning of its name and containing the original XML string.

The JSON dotted notation will look for the root element that is being processed by the pipeline and cross it according to the specification provided in the XML Field Path property.

Example:

In a XML Field Path representation with a.b.c.d, "a" will be searched in the root element. Afterwards, it will be “b”, then "c" and finally "d". If an array is found during the cross process, then the algorithm will create a cross path for each array element. The algorithm replaces all the occurrences of the path defined in XML Field Path.


XML to JSON Transformer in Action

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

{
  "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

  • Input

- Parameters

- XML Field Path: xmlField

- Preserve Original: false

- With Namespace: false

- Remove XML Attributes: false

- All Values As String: false


Output

{
  "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

  • Input

Parameters

- XML Field Path: xmlField

- Preserve Original: true

- With Namespace: false

- Remove XML Attributes: false

- All Values As String: false


  • Output

{
  "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

  • Input

Parameters

- XML Field Path: xmlField

- Preserve Original: false

- With Namespace: true

- Remove XML Attributes: false

- All Values As String: false


Output

{
  "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

  • Input

Parameters

- XML Field Path: xmlField

- Preserve Original: false

- With Namespace: false

- Remove XML Attributes: true

- All Values As String: false


Output

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


XML Transformation with the All Values As String parameter enabled

  • Input

Parameters

- XML Field Path: xmlField

- Preserve Original: false

- With Namespace: false

- Remove XML Attributes: true

- All Values As String: true


Output

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

}
Did this answer your question?