Merge 2 Json arrays in Logic App by using Azure Monitor Query
Published Apr 27 2021 03:10 AM 5,593 Views
Microsoft

In Logic App, sometimes we need to merge two Json arrays into one based on reference ID.

The normal way is to iterate one array -> filter the items with same ID in another array -> insert the items.

But there's another achievement to do it is using "Azure Monitor Logs" connector and pass arrays as dynamic content in the query which will be less time consumption and higher performance. 

 

Background

In Azure Monitoring query, we can not only retrieve the data which stored in the database, but also pass dynamic content into it and convert it as data table.

https://docs.microsoft.com/en-us/azure/data-explorer/kusto/query/scalar-data-types/dynamic

 

Scenario

I have 2 Json arrays like following:

Array 1:

[

            {

                "@odata.type": "#microsoft.graph.user",

                "id": "e9b26715-b94e-xxxxxxxxxxxxxxxxx",

                "userPrincipalName": "user2@xxx.onmicrosoft.com"

            }

            ……

            {

                "@odata.type": "#microsoft.graph.user",

                "id": "8e98ee70-d769-xxxxxxxxxxxxxxxxx",

                "userPrincipalName": "user3@xxx.onmicrosoft.com"

            }

]

 

Array2:

[

            {

                "@odata.type": "#microsoft.graph.user",

                "id": "e9b26715-b94e-xxxxxxxxxxxxxxxxx",

                "displayName": "user2"

            },

            ……

            {

                "@odata.type": "#microsoft.graph.user",

                "id": "8e98ee70-d769-xxxxxxxxxxxxxxxxx",

                "displayName": "user3"

            }

]

 

In this scenario, these 2 arrays need to be merged into one array which has id, displayName and userPrincipalName field.

We only need to create a Azure Monitor Log – Run query and list result action like following and pass these 2 json arrays as dynamic content ( Please use mv-expand instead of mvexpand since mvexpand limit the results to 128 items )

Drac_Zhang_0-1618542612461.png

 

 

After run the LA, we can get the merged array.

Drac_Zhang_1-1618542701377.png

 

Limitation

The values of type dynamic is limited to 1MB, so this workaround not support for handling large size data.

 

6 Comments
Microsoft

Thank you Drac for your sharing, very useful! @Drac_Zhang 

Copper Contributor

I found this post great. I am trying to do this. Thank you @Drac_Zhang ... Quick question is there any Azure Cost associated to just using the Azure Monitor to perform this dynamic tasks... 

thanks.. 

Microsoft

@lfgarbi As far as I know, there's no cost

Copper Contributor

Thank you very much @Drac_Zhang ... 

Copper Contributor

Wow this is game-changing, thanks Drac.  One thing I noticed with my test was that using "mvexpand" limited me to 128 results.  Changing this to "mv-expand" returned my full dataset.

Microsoft

@Alan Roberts Thanks for your information, blog updated

Co-Authors
Version history
Last update:
‎Jan 18 2023 01:03 AM
Updated by: