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

Select action reducing the Dataverse rows to a simple array of five county names

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

JSON array output from the Select action listing five counties

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

Initialize variable action creating a second array with one additional county

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

Compose action using the union function to merge the two arrays

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

Set variable action assigning the merged array from the Compose output

The variable varCombined contains the merged JSON array shown below

Merged JSON array containing the counties from both arrays

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

Search posts

Get in touch

Fill out the form and I’ll be in touch.