The Power Automate Xml function lets you convert JSON to XML in Power Automate flow. Just pass a string of a JSON object to the xml function and retrieve the equivalent XML representation for the given JSON object.
In this article, I’ll introduce you to the xml function and will provide a step-by-step guide on how to use the function in a Microsoft flow.
Power Automate Xml Function
Convert a string containing a JSON object to its corresponding XML version.
Syntax
xml('<value>')
Input parameters
- value (mandatory): The input should be a string containing a JSON object, which should have only one top-level property and cannot be an array. The backslash (\) should be used as an escape character for double quotation marks (“) within the JSON object.
Return value
- Returns the XML for the given JSON object.
Power Automate Xml Example
xml(json('{ "name": "John Doe" }'))
=> <name>John Doe</name>
How To Convert JSON To XML With The Power Automate Xml Function
In this little example we convert a JSON string to XML in Power Automate.
We will be using the following JSON.
{
"Contact":
{
"name": "John Doe",
"email": "[email protected]"
}
}
The equivalent XML generated by the Power Automate Xml function should look like this.
<Contact>
<name>John Doe</name>
<email>[email protected]</email>
</Contact>
Follow the steps to convert the JSON to XML in a Power Automate flow by using the xml function in an expression.
-
Create a new flow with trigger ‘Manually trigger a flow’
New flow
-
Add a new step by clicking on ‘+ New step’
New step
-
Filter for ‘initialize’ and click on the ‘Initialize variable’ action
Add Initialize variable action
-
Setup Initialize variable action: 1) set a name, 2) set type to Object and paste the JSON from the top of the article into Value
Setup Initialize variable action
-
Add a new compose step by filtering for ‘compose’ and by clicking on the ‘Compose’ action
Add a compose action
-
Setup compose 1) click into inputs (popup comes up), 2) click on ‘Expression’, 3) set the function to ‘xml(variables(‘json’))’, 4) click on OK
Setup compose with the Power Automate xml expression
-
Do a test run
Result – Power Automate convert JSON to XML