Convert from XML
Input
✳️ Any (JSON
)
Ouptut
✳️ Any (JSON
) (Passthrough)
Response Data (
object
) (Optional)
Summary
This action takes a string containing an XML document (e.g. from a previous API call or other input), parses it, and converts it to JSON using the rules below.
Root Element Handling
By default, the root element is omitted, so:
<Results>
<Name>John Doe</Name>
<Email>jdoe@example.org</Email>
</Results>
Becomes:
{
"Name": "John Doe",
"Email": "jdoe@example.org"
}
When the option Include Root Element is enabled, the output instead is:
{
"Results": {
"Name": "John Doe",
"Email": "jdoe@example.org"
}
}
Output Merging
By default, the Output Property is blank. This causes the contents to be merged into the existing data context.
Take, for example, this sample existing data context, with some trigger metadata and IQA results:
{
"_metadata": {
"id": "01K63E05595ZXD3Y5W8B9SZFFN"
},
"iqaResults": [...]
}
When the Output Property is blank, and Include Root Element is off, the resulting data context is:
{
"_metadata": {
"id": "01K63E05595ZXD3Y5W8B9SZFFN"
},
"iqaResults": [...],
"Name": "John Doe",
"Email": "jdoe@example.org"
}
When the Output Property is specified (for example, xmlData
) and Include Root Element is off:
{
"_metadata": {
"id": "01K63E05595ZXD3Y5W8B9SZFFN"
},
"iqaResults": [...],
"xmlData": {
"Name": "John Doe",
"Email": "jdoe@example.org"
}
}
Finally, be careful when both an Output Property is specified, and Include Root Element is enabled, because your resulting context will be this, which includes two “root elements” of sorts:
{
"_metadata": {
"id": "01K63E05595ZXD3Y5W8B9SZFFN"
},
"iqaResults": [...],
"xmlData": {
"Results": {
"Name": "John Doe",
"Email": "jdoe@example.org"
}
}
}
XML to JSON Conversion Rules
All examples below assume that the “Include Root Element” setting is off.
Nested Elements
Nested elements are typically represented as nested JSON objects.
<Result>
<Item>
<Name>John Doe</Name>
<Email>jdoe@example.org</Email>
</Item>
</Result>
{
"Item": {
"Name": "John Doe",
"Email": "jdoe@example.org"
}
}
Arrays
Anywhere that two or more elements exist at the same scope with the same name will create an array.
<Result>
<Item>
<Name>John Doe</Name>
<Email>jdoe@example.org</Email>
</Item>
<Item>
<Name>Jane Doe</Name>
<Email>jane@example.org</Email>
</Item>
</Result>
{
"Item": [
{
"Name": "John Doe",
"Email": "jdoe@example.org"
},
{
"Name": "Jane Doe",
"Email": "jane@example.org"
}
]
}
Attributes
Attributes appear as properties under the element, prefixed with the @
character:
<Result>
<Element1 Name="Joe" Title="Admin" />
<Element2 Name="Jane" Title="Owner">
<Course>9000-23</Course>
</Element2>
</Result>
{
"Element1": {
"@Name": "Joe",
"@Title": "Admin"
},
"Element2": {
"@Name": "Jane",
"@Title": "Owner",
"Course": "9000-23"
}
}
Mixed Text Content
Mixed text content will appear as a property under the parent element with the #text
property name, for example:
<Result>
<Key Name="A1" />
<Key Name="A2">
<Value>true</Value>
This key is an example.
</Key>
</Result>
{
"Key": [
{
"@Name": "A1"
},
{
"@Name": "A2",
"Value": "true",
"#text": " This key is an example. "
}
]
}
XML is a whitespace-sensitive language. Whitespace before and after an element (including newlines and indentation) is converted to at most 1 space character.
Be sure to separately trim any properties that may have whitespace around them prior to usage. This action does not support trimming of XML properties or text values.
CDATA Strings
CDATA tags (tags wrapped in <![CDATA[ … ]]>
) are respected and parsed correctly as text nodes. They are available as a property named #cdata-section
.
<Result>
<Key Name="A1" />
<Key Name="A2" />
<Key Name="A3" />
<Key><![CDATA[
<message>
This is a CDATA string.
It includes newlines and whitespace.
</message>
]]></Key>
</Result>
{
"Key": [
{
"@Name": "A1"
},
{
"#cdata-section": " <message> This is a CDATA string. It includes newlines and whitespace. </message> "
}
]
}
Properties
Name | Type | Templatable | Notes |
---|---|---|---|
XML Input | Text | The XML document to parse. The XML processing instruction preamble, | |
Include Root Element | Checkbox | If checked, the root element of the XML document is included, and all other elements are accessible under that root object. This is in addition to the output property name. If no root element is present on the XML document (i.e. the root of the document contains 2 or more elements as siblings), then a root element is automatically created and applied, named | |
🅾️ Output Property | Text | Optional. The property name to store the converted XML document data under. If empty but Include Root Element is on, then the document’s root element will be added to the data pipeline. If empty and Include Root Element is off, then the full contents of the XML document are merged with the existing data pipeline contents. |