Create Typed Messages in Logic Apps Using Parse JSON
  • Updated on 07 Mar 2020
  • 2 minutes to read
  • Contributors
  • Print
  • Comments
  • Share
  • Dark
    Light

Create Typed Messages in Logic Apps Using Parse JSON

  • Print
  • Comments
  • Share
  • Dark
    Light

#ServerlessTips - Azure Logic Apps
Author: Kent Weare Integration MVP

Having structured, or typed messages, becomes very important in Azure Logic Apps as it allows you to use data elements/attributes/fields in downstream actions as Dynamic Content. The problem is, how do we generate these typed messages when we don’t have XSD schemas, or OpenAPI (aka Swagger) API definitions? The answer lies in an action called Parse JSON.

Using Parse JSON allows us to take a sample JSON message and apply a JSON schema to it, without having to understand how to create a JSON schema.

Let’s look at an example. Imagine we are running an Apartment building complex. We want to be able to provide our tenants with the ability to log a maintenance ticket by sending an email into a mailbox. However, we don’t want to be manually creating these tickets, we want to automate them. As a result, we will call an API in our Work Order Management system that will take care of it for us.

1-design

This API will return a response that can be useful in updating our customer with a context-relevant email. The problem is, our API doesn’t have a typed message body that we can take advantage of if we want to send a personalized email back to our customer.

2-output

In order to provide a relevant response back to our customer, we can use the Parse JSON action and use this output from our HTTP call to generate a JSON schema. We can click on + New step within the Logic Apps designer and then search for Parse JSON.

3-ParseJSON

We now want to click on Use sample payload to generate schema and then can paste in the output from our API call and click Done.

4-sample

We need to populate our Content field by adding the Body - Dynamic content from our API Call. In addition, we will discover our Schema text area has been populated with our JSON schema that was generated from our sample.

5-body

Since we used the Parse JSON action, we can now see Dynamic Content that includes our data attributes from our API call. This allows us to provide a personalized email back to our customer.

6-replyToMessage

Conclusion

Using typed messages unlocks opportunities to leverage the data that is being exchanged between Azure Logic Apps and other systems. For some services, they will include an API specification, like Swagger, which helps immensely. But, when an API specification is not available, we can use a sample message and Parse JSON to create typed messages for us.

Was this article helpful?