Friday Fact: It is possible to create an XML first-class experience inside Logic Apps.

By default, Logic Apps provides a good first-class experience for JSON, that means when we receive a JSON message, we can tokenize the elements by using a JSON schema inside, for example, a Parse JSON action:

This will basically create shortcuts or pointers to the fields of the message that we can easily use in other actions without worrying about the query path to each field:

These tokens or points are, in fact, shortcuts to the query path of those fields providing a good first-class experience:

  • body(‘Parse_JSON’)?[‘firstName’]
  • body(‘Parse_JSON’)?[‘lastName’]

These two are simple, but they can be a little bit more complex:

  • outputs(‘Compose_Response_JSON’)[‘Result’][‘Address’][‘PostalCode’])

Unfortunately, many people complain that we don’t have the same capabilities for XML messages. And that’s true. By default, XML messages don’t have this first-class experience to access the fields since the message, but that doesn’t mean that we cannot have that experience, either!

A quick and simple workaround to implement a first-class experience for XML messages inside Logic Apps is to use the JSON () expression to convert the XML into its JSON equivalent. Know more details about how you can apply this conversion here: Logic App Best Practices, Tips, and Tricks: #41 How to convert XML into JSON inside Logic Apps

For example, if we have the following XML message:

<Person>
	  <Firstname>Sandro</Firstname>
	  <Lastname>Pereira</Lastname>
</Person>

We can use the following expression to convert the XML message to JSON:

  • json(xml(outputs(‘Compose_XML’)))

Of course, then we need to provide a JSON Schema that corresponds to that message. and that will allow you to have a first-class experience for that XML message

Just a simple trick that can help you in many processes.

To lazy to read? We’ve got you covered! Check out our video version of this content!

Join us next Friday for another Friday Fact!

Hope you find this helpful! If you enjoyed the content or found it useful and wish to support our efforts to create more, you can contribute towards purchasing a Star Wars Lego for my son!

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