Hi Readers,
Logic apps enforces json based message data processing, you can relate this concept with the BizTalk Server where xml based data processing standards are being enforced:
Applications | Data Processing Standard |
BizTalk | XML |
Logic Apps | JSON |
In BizTalk, it is very easy to parse json data into xml. There is a built-in pipeline available in Microsoft BizTalk Server 2013 Edition to implement this, but it gets tricky when you have to do the similar thing in a logic app. I am going to show you an example on how to parse json data into xml in logic apps…
-
In my example, I have created a custom API, which returns a list of employee names in a form of json data.
-
My objective is to create a text file in a blob container with a name of “Sovit.txt” and it should contain the data in the xml form of the above employee names, using a Logic App.
- It took a fair amount of time to figure out how to do this and I am sharing this with you to save your precious time.
-
I have created a logic app with a name of TestEmployeeApp and it has three easy steps:
- First step is a manual trigger, which I will be using to call/trigger this logic app, manually. Second step is an action, that calls a custom api, which returns the employee names data in Json. Third and final step is an action, which will create a file in a Blob container.
- Note: that I have used predefined xml function of WDL, to parse json data into xml.
- Note: In function xml (), you can only give one json property at a time. Multiple json objects or json object with multiple properties cannot be converted in a single go.
-
I had three employees to parse, so let’s see how I did it.
- The above image is the third step of my logic app, I have created xml data with a root node of “Data” along with the concatenation of xml result of each json object one by one. Please see the highlighted code above.
- ‘concat’ is a string function used to combine all the string values together.
- Note: in the xml function, the input parameter is the single json object from the body of the action ‘Employee_Get’.
- I have used the xml function thrice because I had three json objects to parse. If you have multiple json objects, you can use ‘forEach’ loop to loop over and convert each item to xml using the xml function.
- Finally, I have assigned the output xml data to the body of the action, which creates a file in the blob container with the name “sovit.txt”, See the picture above.
- You can download the complete code through this link http://sovitstorage.blob.core.windows.net/logicappcode/EmployeeXmlParse.txt.
- Let me know if you are facing any issues with xml parsing in logic apps and BizTalk.
Hi,
Trying to download the txt:
InsufficientAccountPermissions
The account being accessed does not have sufficient permissions to execute this operation. RequestId:bfb45487-0001-00fa-7e53-6d83f9000000 Time:2017-01-13T04:14:45.8798971Z
Thanks for your help
Francesco
LikeLike