Join JSON Arrays

This is how to join two JSON arrays with Power Automate.  The first array is generated from Dataverse.  The ‘List rows’ step extracts the first 5 rows from a table, in this case the Counties of England

join json array

The output from List rows is a JSON that contains the data for each column in the County table for the 5 rows retrieved.  I’m only interested in a small subset of that data so using a Select step places the 5 county names into a much simpler JSON array

And here is the JSON array that’s the output from the Select step

I want to append a second array to the first.  The second array is generated manually using the Initialise Variable step below.  The type of variable should be array. I’ve called the second array varAdditionalCountyName and it contains the same name/value pair as the first array and for simplicity it contains just one element

To merge the 2 arrays together, use a Compose step with the Union function

The full Union formula is below

union(body('Select'),variables('varAdditionalCountyName'))

The Union function takes all the elements from the first array and adds the element from the second array.  If there are duplicate elements, either within the same array or across both arrays, the Union function removes them, which can be helpful

Finally assign the output from the Compose step into another array variable

The variable varCombined contains the merged JSON array shown below

That’s how to join 2 arrays.  In the next post I’ll demonstrate how to pass a JSON array from a parent to a child flow

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top