Skip to main content

Convert between XML/JSON with added XSLT transformation in Logic Apps

motivation

To run simple XML/JSON transformations, the built-in Logic Apps expressions json and xml do the job fine. When additional mapping, selection, or custom structures are required, the built-in expressions might be too complex to set up.

Invictus provides a XML/JSON Converter component which converts XNL/JSON contents, while running a XSLT transformation beforehand (stored in Azure Blob Storage). Removing the complexity from the Logic App

Available endpoints

  • /api/XmlToJson: transforms incoming request with XML contents to a response with the JSON result.
  • /api/JsonToXml: transforms incoming request with JSON contents to a response with the XML result.

The /api/XmlToJson endpoint transforms a provided BASE 64-encoded XML contents to a BASE 64-encoded JSON result. A XSLT transformation (stored in the Azure Blob Storage container called xmltojsonconfigstore) gets run beforehand to map the request in the right structure. This stored transformation gets gets referenced in the request.

Request propertyRequiredDescription
ContentyesThe BASE 64-encoded XML contents.
ConfigNameyesThe file name of the XSLT transformation, stored in Azure Blob Storage.
ContextnoThe dictionary providing context to the conversion, gets copied 1:1 to the response.
XPathnoThe XPath expression that selects a specific XML node before the XSLT transformation.
JPathnoThe JPath expression that selects a specific JSON property after the XSLT transformation.
Full request JSON body example
// POST /api/XmlToJson
{
"Content": "eyJFbnZlbG9wZSI6IHiU2FsZXNPcmRlckluIjp7ICAgICAgICAg...." ,
"ConfigName":"IDD038-inbound.xsl",
"XPath": "/CustomerAccount/Message",
"JPath": "$.Envelope",
"Context": {
"x-conversationId": "29500405-d7cf-4877-a72b-a3288cff9dc0"
}
}
Full response JSON body example
// 200 OK <- /api/XmlToJson
{
"Content": "ejHixZlwI9HiU2FsxNPcmRluIjp7ICAgICagICa...",
"Context": {
"x-conversationId": "29500405-d7cf-4877-a72b-a3288cff9dc0"
}
}

Customization

Related Bicep parameters

The following Bicep parameters control the inner workings of the XML/JSON Converter component. See the release pipeline step of the deployment of the Invictus Framework to learn more.

Bicep parameterDefaultDescription
storageAccountNameinvictus{resourcePrefix}storeThe name of the Azure Storage Account (used by other Framework components as well) where the xmltojsonconfigstore Azure Blob Storage container will be located.
xmlJsonConverterScaling{ cpuResources: '0.5', memoryResources: '1.0Gi', scaleMaxReplicas: 1, scaleMinReplicas: 0, concurrentRequests: 10 }The Container App options to control scaling. See scaling rules in Azure Container Apps.
xmlJsonConverterFunctionNameinv-{resourcePrefix}-xmljsonconverterThe name of the Azure Container App to be created for the XML/JSON Converter component.