Skip to main content
Version: 1.28 (Current)

Parse XML Into JSON Tokens

Audience: Low-code Engineers

Skill Prerequisites: Actions, Tokens, JSON

Reads an XML string, such as the response of a SOAP or legacy API, converts it to JSON, and turns it into tokens. Each token starts with the Base Token Name you choose, followed by the name of the root element, for example [Order:order.customer].

After the conversion, the tokens are created exactly like Parse JSON Into Tokens does: nested elements use dot notation, and repeated elements become a JSON array that isn't expanded.

Typical Use Cases​

  • Read values from an XML response of a Server Request, for example a status code or a tracking number
  • Read attributes of an XML element, for example [Order:order.@id]
  • Turn a repeated XML element into a JSON array, so Create List from JSON can load it

Don't use it to​

Action NameDescription
Parse JSON Into TokensDoes the same for JSON. Also useful to read the items of an array token created by this action.
Server RequestCalls an API. Its response is often the input of this action.
Create List from JSONLoads a JSON array into a list, for example the array of a repeated element.
Create JSON ObjectBuilds a JSON object from name, value and type rows.

Input Parameter Reference​

ParameterDescriptionSupports TokensDefaultRequired
XML StringThe XML to read, usually a token such as [ApiResponse]. It must be a well-formed XML document with one root element. An XML declaration such as <?xml version="1.0"?> is allowed.Yesempty stringYes

Output Parameters Reference​

ParameterDescriptionSupports TokensDefaultRequired
Base Token NameThe start of every token created, for example Order for [Order:order.customer]. Enter the name without brackets. If it's empty, the action fails with No Base TokenName was given.Noempty stringYes

How the XML becomes JSON​

The root element becomes the only property of a JSON object, so every token path starts with the root element's name. Then:

XMLJSON
Element with only text: <customer>Jane</customer>"customer": "Jane"
Attribute: id="7""@id": "7"
Element with attributes and text: <note lang="en">Hi</note>"note": { "@lang": "en", "#text": "Hi" }
Empty element: <empty/>"empty": null
Element that appears once: <item sku="A1"/>"item": { "@sku": "A1" }
Element that appears several times under the same parent"item": [ {...}, {...} ]
CDATA section"#cdata-section": "..."
Prefixed name: <p:code>"p:code"
Namespace declaration: xmlns:p="urn:p" or xmlns="urn:x""@xmlns:p": "urn:p" or "@xmlns": "urn:x"

All values are text. Numbers such as 2 and booleans such as true stay as the text in the XML.

How the JSON becomes tokens​

The JSON is turned into tokens like Parse JSON Into Tokens does. With Base Token Name set to Order, this XML:

<order id="7">
<customer>Jane Doe</customer>
<note lang="en">Deliver after 5 PM</note>
<item sku="A1"><qty>2</qty></item>
<item sku="B2"><qty>1</qty></item>
</order>

creates these tokens:

TokenValue
[Order:order]The whole order element, as indented JSON
[Order:order.@id]7
[Order:order.customer]Jane Doe
[Order:order.note]The note element, as indented JSON
[Order:order.note.@lang]en
[Order:order.note.#text]Deliver after 5 PM
[Order:order.item]The two item elements, as an indented JSON array

The item elements aren't expanded, because they became an array. [Order:order.item] holds:

[
{ "@sku": "A1", "qty": "2" },
{ "@sku": "B2", "qty": "1" }
]

To read them, load [Order:order.item] with Create List from JSON, or parse it with Parse JSON Into Tokens. With base name Items, that gives [Items:0.@sku], [Items:0.qty], [Items:1.@sku] and so on.

Considerations​

  • Include the root element in the path. Tokens look like [Order:order.@id], not [Order:@id].
  • One element or several changes the JSON. If an element appears once, it's an object and its children get tokens, for example [Order:order.item.@sku]. If it appears twice or more, it's an array and its children don't get tokens. When the number of elements varies, treat the token as data you load with Create List from JSON, and check what you get.
  • Force an array. To always get an array, even for one element, add json:Array="true" to the element and declare the namespace on a parent: xmlns:json="http://james.newtonking.com/projects/json". This only helps when you control the XML.
  • Namespaces. Prefixes are kept in names, for example [Soap:soap:Envelope.soap:Body]. Namespace declarations become @xmlns... tokens.
  • Invalid XML fails the action with the XML parser's error, for example Data at the root level is invalid or Root element is missing for an empty string. Use a condition, or the On Error actions of Execute Actions, if the input can be empty or broken.
  • Tokens in XML String aren't escaped. Token values are pasted as they are. If you build the XML yourself, a value with & or < breaks it.
  • The other token rules of Parse JSON Into Tokens apply, for example token names aren't case-sensitive and old tokens with the same base name aren't removed. XML values are always text, so booleans aren't capitalized and dates aren't rewritten.

Examples​

tip

To understand how to use the below examples, please see Running Examples.

1. Read a shipment status from an XML response​

A Server Request saved a response such as <shipment id="S-100"><status>Delivered</status><signedBy>J. Doe</signedBy></shipment> in the ShipmentResponse token. This action creates [Shipment:shipment.@id], [Shipment:shipment.status] and [Shipment:shipment.signedBy].

{
"Title": "Parse XML Into JSON Tokens",
"ActionType": "ParseXMLIntoTokens",
"Description": "Read the shipment status",
"Condition": "[ShipmentResponse] != \"\"",
"Parameters": {
"Xml": "[ShipmentResponse]",
"BaseTokenName": "Shipment"
}
}

The actions that follow can check [Shipment:shipment.status] == "Delivered".

2. Load repeated elements into a list​

The CatalogXml token holds <catalog><product code="A1">Pen</product><product code="B2">Pad</product></catalog>. The first action creates [Catalog:catalog.product], a JSON array such as [{"@code": "A1", "#text": "Pen"}, ...]. The second loads it into ProductsList, whose items have the @code and #text properties.

[
{
"Title": "Parse XML Into JSON Tokens",
"ActionType": "ParseXMLIntoTokens",
"Description": "Convert the catalog",
"Parameters": {
"Xml": "[CatalogXml]",
"BaseTokenName": "Catalog"
}
},
{
"Title": "Create List from JSON",
"ActionType": "LoadEntitiesFromJson",
"Description": "Load the products",
"Parameters": {
"JsonModel": "[Catalog:catalog.product]",
"EntityName": "ProductsList"
}
}
]

Revised 09/27/2026