Skip to main content
Version: ACE 5

XML ⇄ JSON

Overview

XML ⇄ JSON allows transforming json to xml and vice versa. This is useful when making xml requests that expect the request body to contain XML (and to transform the received input to json).

Configuration

  • Mode - select the required mode of operation (JSON to XML or XML to JSON)
  • Target path - doc context node on which to place the created xml / json

JSON to XML

  • Attribute key - which key in object should be converted to xml attributes instead of creating as a node
  • Headless xml - if true the xml generated is headless. The default value is true.
  • JSON path - in JSON to XML mode - sets doc node from which to take json to be converted to xml

XML to JSON

  • Attribute key - set the JSON object key onto which to bind XML attributes if those are found on an XML node
  • XML path - sets the doc node from which to take xml to be converted to json should be provided as {{docNode}}
  • Put child nodes in an array - if selected this will convert subnodes of the xml into array items

Examples

Convert JSON to XML

In example below $ value is converted to attributes. Used attribute key can be modified via property Attribute key

Sample flow

steps:
- name: Step xml
config:
mode: JSON to XML
attrKey: $
headlessXml: true
explicitArray: true
targetPath: result
json:
element:
$:
attribute_name: attribute value
child1:
prop: "{{doc_property}}"
child2:
object: "{{doc_object}}"
child3: string value
stepType: xml

Input document

{
"doc_property": "value from document context",
"doc_object": {
"doc_name": "doc_value"
}
}

Execution result

{
"doc": {
"doc_property": "value from document context",
"doc_object": {
"doc_name": "doc_value"
},
"result": "<element attribute_name=\"attribute value\"><child1><prop>value from document context</prop></child1><child2><object><doc_name>doc_value</doc_name></object></child2><child3>string value</child3></element>"
}
}

Convert XML to JSON

Sample flow

steps:
- name: Step xml
config:
mode: XML to JSON
attrKey: $
explicitArray: true
headlessXml: true
targetPath: result
xml: <element attribute="attribute value"><child>value</child></element>
stepType: xml

Execution result

{
"doc": {
"result": {
"element": {
"$": {
"attribute": "attribute value"
},
"child": [
"value"
]
}
}
}
}