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.