As explained in a previous post, Logic Apps has already some basic actions to transform objects and arrays.  However, from the moment transformation between JSON objects becomes more complex, it turns out to be insufficient.  That’s why the brand new Liquid template feature has been released recently.  Let’s check out how it works!

Liquid?

Liquid is a templating engine that uses a simple markup language to produce all sorts of output formats, such as HTML, JSON, CSV, etc…  You can consult the documentation over here.  It’s quite easy to use, you just need to get used to the new syntax.

Within Logic Apps, Liquid templates are used as a kind of XSLT for JSON objects.  This allows you to create more complex transformations on JSON objects, without the need of introducing a custom Azure Function.  Liquid templates are part of the Integration Account.  Behind the scenes, DotLiquid is used.

How to use it?

Define the input format

The input of a Liquid template must be a JSON object.  For this test scenario, I’ve choosen the following sample:

{ 
   "FirstName" : "Toon", 
   "LastName" : "Vanhoutte", 
   "Order" : [ 
      { 
         "Product" : "Pizza Romana", 
         "Quantity" : 6 
      }, 
      { 
         "Product" : "Pizza Funghi", 
         "Quantity" : 1 
      }, 
      { 
         "Product" : "Pizza Margherita", 
         "Quantity" : 3 
      }
   ]
}

Create and upload the Liquid template

  • Create the Liquid template.  This is my test example.
{   
   "Name" : "{{ content.FirstName }} {{ content.LastName }}",   
   "Date" : "{{ "now" | Date: "MM/dd/yyyy" }}",   
   "NumberOfPizzaTypes" : "{{ content.Order | Size }}",   
   "Pizzas" : [   
      {% for pizza in content.Order %}      
      {          
         "Name" : "{{ pizza.Product }}", 
         "Qty" : {{ pizza.Quantity }}      
      },   
      {% endfor %}   
   ]
}
  • Within the Integration Account, navigate to Maps

2017-11-22 00_24_04-integrationaccount - Microsoft Azure

  • Click Add and specify a name, Liquid as the type and select the liquid template from your pc.

2017-11-22 00_26_30-Add Map - Microsoft Azure

Add the Liquid transformation action

  • First of all, make sure your Logic Apps is linked with an Integration Account

2017-11-22 00_28_34-Workflow settings - Microsoft Azure

  • Add and configure the action in your Logic App.  It’s straightforward to use

2017-11-22 00_37_15-Logic Apps Designer - Microsoft Azure

Test the Liquid transformation

  • Execute the Logic App and the Liquid action should return the following JSON object:
{
   "Name": "Toon Vanhoutte",
   "Date": "11/21/2017",
   "NumberOfPizzaTypes": "3",
   "Pizzas": [
      {
         "Name": "Pizza Romana",
         "Qty": 6
      },
      {
         "Name": "Pizza Funghi",
         "Qty": 1
      },
      {
         "Name": "Pizza Margherita",
         "Qty": 3
      }
   ]
}

Conclusion

This functionality is really helpful in Logic Apps.  Whereas BizTalk Server has XML as a native language and XSLT as a transformation engine, Logic Apps has native JSON support, with Liquid templates as the mapping tool.  Some additional thoughts from my side:

  • At the moment, there’s no documentation on this brand new feature.  It would be good to have that coming real soon!
  • The Logic Apps Liquid transformation engine seems to deviate from the original Liquid documentation.  The documentations states that filters should be lower case, while Logic Apps expects the first letter to be uppercase (“Date” instead of “date” – “Size” instead of “size”).  Probably related to the DotLiquid implementation under the hood.
  • The great thing about Liquid templates is the fact that it can produce all types of outputs.  However, Logic Apps limits its usage to pure JSON outputs.  Would be great to have the opportunity to leverage liquid templates to create HTML, TXT and other output types.

I hope you’ve enjoyed this one!

Toon

About me

Hi! I’m Toon Vanhoutte, a hands-on Azure architect – based in Belgium – with a big passion for teaching and helping people out. I’m happy to assist you during your Azure journey with high-quality advisory and I would love to teach you Azure’s possibilities via my tailored training courses.

Subscribe to the blog