Azure Functions to Convert XML into JSON

Why do we need this Azure Function? This may be the question that you are asking yourself at the moment. Because if we are using Azure Integration Services, we can easily use: 

  • The json() expression that returns the JSON type value or object for a string or XML inside Logic Apps
  • Or the xml-to-json policy that converts a request or response body from XML to JSON inside API Management.

Well, our main objective in creating this function was to be used in Azure API Management to overcome some non-conforming behaviors while converting XML to JSON of the xml-to-json policy, mainly if that XML contains prefixes.

As you may know, prefixes are used inside XML to prevent name conflicts. And when we use them, a namespace for the prefix must be defined. They will work as an abbreviation of the full XML namespace. The namespace declaration has the following syntax:

  • xmlns:prefix=”URI“.

allowing MyField to be written in this namespace as prefix:MyField rather than, say, {URI}MyField

And in Enterprise Integration solutions, it is quite normal to see XML documents and Schemas using several prefixes.

Later in another blog post, we will explain the issue behind the decision to create this Azure Function in detail.

And what does this Azure Function do?

The ConvertXMLtoJSON Azure Function, as the name mentions, converts an XML payload to JSON. This function can be used to modernize APIs based on XML-only backend web services.

Once again, our main objective in creating this function was to be used in Azure API Management to overcome some non-conforming behaviors of the xml-to-json policy. However, it can be used in other scenarios.

Where can I download it?

You can download the complete Azure Functions source code here:

Hope you find this helpful! So, if you liked the content or found it useful and want to help me write more, you can buy (or help me buy) my son a Star Wars Lego! 

Thanks to my team member Luís Rigueira for helping me realize and implement this idea.

Author: Sandro Pereira

Sandro Pereira lives in Portugal and works as a consultant at DevScope. In the past years, he has been working on implementing Integration scenarios both on-premises and cloud for various clients, each with different scenarios from a technical point of view, size, and criticality, using Microsoft Azure, Microsoft BizTalk Server and different technologies like AS2, EDI, RosettaNet, SAP, TIBCO etc. He is a regular blogger, international speaker, and technical reviewer of several BizTalk books all focused on Integration. He is also the author of the book “BizTalk Mapping Patterns & Best Practices”. He has been awarded MVP since 2011 for his contributions to the integration community.

Leave a Reply

Your email address will not be published. Required fields are marked *

turbo360

Back to Top