Transforming JSON TO CSV using Logic Apps and Liquid Templates

Brief about Liquid Templates

Created by Shopify, Liquid Templates have been a burning issue for transformations of object notation payloads like JSON, XML, CSV. The fluidity of liquid filters and tags makes the transformation dynamic and easy to achieve. Manipulating input with different filters serves as an essence of Liquid. The use of uncomplicated delimiters renders the content in desired format.

JSON Data Input

I have a requirement of creating a customized CSV (Comma separated value) file using a JSON input. For the demo purpose, I have the following json input.

Json Input

Liquid Template

To transform any input using liquid, a template has to be created. Liquid template represents a file with ‘.liquid’ extension. We write logic using liquid tags, iterations, filters that renders the content, transforming input file to output payload.

For the json input, that we are using, I have improvised a customization in person’s name. In the csv file, the name should be string comprising of first name, first letter of middle name and last name.

I have created following liquid template for required results.

Liquid Template

Logic Apps

Azure cloud provides a remarkable service to create automated workflows. Actions and triggers orchestrate tasks in a codeless and effortless way. There are connectors from Cloudmersive, Apptigent, and Microsoft to convert Json to Csv format. Creating a customized csv output can be done by liquid template.

Integration Account

Azure integration account stores B2B artifacts such as Maps, Schemas, Agreements, Certificates and Assemblies. The liquid template that we used, should be saved inside maps, as it be used to map the json to csv file.

Adding Liquid Map to Integration account

Creating Logic Apps Workflow

Before creating the workflow, we have to go to workflow setting to add the integration account to logic app.

For this demo purpose, I have created a simple Http request-response model logic app with a Liquid connector and Azure Blob Storage connector. The action used for liquid connector is ‘Transform JSON to Text’. Blob storage connector uses ‘Create Blob’ action. Transformed content is saved to blob with a ‘filename.csv’ format. The workflow looks like-

Logic App Workflow

I am using Postman Rest Api tool to send http request, which triggers the logic app. Json content is sent in the body of request. The Liquid connector action uses http trigger body content and a liquid map from integration account to transform input json to a text value in comma separated values format. We are saving the transformed output to blob storage with .csv file extension.

Postman Request

After request is processed, the logic app response is sent as the transformed output as below.

Postman Response

We can download the csv file rom blob storage to view the values in csv format.

As we can conclude, with Liquid templates, converting a Json content to Csv has become an easy feat. The appropriate use loops and filter tags results in desired output for JSON, XML and CSV formats.

Because of its dynamic nature, liquid templates are being used by numerous tech companies such as Jekyll, Salesforce, Desk, GoDaddy, Fedora, Lucid, Flipkart, InSales, Carnival and many more.

For more information about Liquid Templates, refer to following Link:

https://shopify.github.io/liquid/

For more information about Azure Logic apps, refer to following Link:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-overview

For more information about Azure Integration Account, refer to following Link:

https://docs.microsoft.com/en-us/azure/logic-apps/logic-apps-enterprise-integration-create-integration-account?tabs=azure-portal

--

--

--

Technocrat, Information Geek, Music Enthusiast, Coffee Lover, When bored can be found reading sappy Romance Novels

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

What is Object-oriented programming

The 2 Surprising Factors That Determine Whether Background Removal API Will Work

Setup VPC peering connection in Google Cloud

A Streaming Pattern in Go for large-scale Infrastructure

CS371g Final Entry

Women Who Code Mentorship Program 4.0- Week 2

Coding vs. Knowing Coding

The Ultimate Beginners Guide: Coding and Deploying a Beautiful Portfolio Website

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anuradha Tupsundare

Anuradha Tupsundare

Technocrat, Information Geek, Music Enthusiast, Coffee Lover, When bored can be found reading sappy Romance Novels

More from Medium

Users , Groups provisioning with SCIM 2.0

How to build a simple Bottom Navigation Bar in Flutter

API Testing with Postman- Part 1- Setup

Get quick knowledge on Application Framework.