How to Convert XML to JSON using Power Automate?

In this Power Automate tutorial, we will see how to convert XML to JSON using Power Automate.

For example, we will convert the XML code to JSON using Power Automate, like below. Then we will send the JSON data via email by parsing it.

For this, we will create an Instant cloud flow that will trigger manually, taking the user input as an XML file (containing product details) and converting content from base 64 to string using Power Automate. After that, we will convert XML to JSON using JSON().

Once it is converted, we will parse the JSON, create an HTML table, and email the recipients.

Microsoft Power automate loop through XML data insert into excel

How to convert XML to JSON using Power Automate

Here we will see an example of how to convert XML files to JSON using Power Automate.

Step 1: Log in to Power Automate, then click on +Create -> select Instant cloud flow.

power automate xml to json

Then provide the flow name and select Manually trigger a flow action. Then click on Create.

How to convert xml to json in Microsoft Power automate

Now, you can see the Manually trigger a flow action is added to the flow page. Now expand the action -> click on Add an input ->select File inputs.

Microsoft power automate xml file to json

Step 2: Now we will convert the base64 to string using Power Automate, so, click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expression:
base64ToString(triggerBody()['file']['contentBytes'])
Microsoft power automate xml to json

Step 3: Now we will convert XML string to JSON using Power Automate, so click on the +New step -> select Compose action. Then provide the below information:

  • Inputs: Provide the below expressions:
json(xml(outputs('Compose_-_base_64_to_string')))
Microsoft power automate convert xml to json

Step 4: Now we will parse the JSON, so click on the +New step and select Parse JSON action. Then provide the below information:

  • Content: Select the output of the above compose action from dynamic content.
  • Schema. To get the schema, click on the Generate from sample button and provide the output of the above compose action. Then click on Done.
Power automate convert xml to json

Step 5: After that, we will create html table, so click on the +New step -> select Create HTML table action. Then provide the below information:

  • From: Select the product from the dynamic content.
How to convert xml to json Power automate

Step 6: At last, we will send an email with the above Html table, so click on the +New step -> select Send an email (V2) action. Then provide the below information:

  • To: Provide the email id whom you want to send an email
  • Subject: Provide the subject of an email.
  • Body: Select the output -Create Html table action from dynamic content.
How to convert xml to json Microsoft Power automate

Step 7: Now run the flow manually; for this, save the flow, click on the Test icon -> select the Manually option -> click on the Test button. Then click Import and select the XML file -> click on the Run flow button. You can see your flow run successfully.

See also  How to Copy New Files from Your PC to SharePoint using Power Automate?

Now go to Outlook; you can see the email will look like below:

power automate xml file to json

This is an example of how to convert XML files to JSON using Power Automate.

Conclusion

In this Power Automate tutorial, we saw how to convert XML files to JSON using Power Automate.

You may like the following tutorials:

>