web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Update JSON data withi...
Power Automate
Answered

Update JSON data within an Array

(0) ShareShare
ReportReport
Posted on by 18

Getting stuck on something that I feel should be easy, so I'm guessing I'm missing something simple...

 

I have some data that looks like this:

 

trentbooks_0-1657305245627.png

 

I use an HTTP call to get some data from a website we use to manage these pipelines, and then I'd like to loop through these 5 array elements and - if the pipeline_id matches what comes from the HTTP call - I'd like to increment the 'count' by 1, and then increment the 'value' by whatever the value of the current item is from the HTTP call. I have tried using both Compose and Select and both choke, so I can only assume I'm doing it wrong. Any help would be much appreciated!

 

Attempt 1 - Compose

With compose, I used this as the input:

 

setProperty(variables('Pipelines')[variables('PipelinesIndex')],'count',add(variables('Pipelines')[variables('PipelinesIndex')]?['count'],1))

 

Here is the explanation of the variables:

variables('Pipelines') is the data I have in the screenshot above.

variables('PipelinesIndex') is just the index value of the loop as it iterates through variables('Pipelines')

 

So basically if I find a match between the pipeline_id's, then I try to update the count by 1. Similarly, I do this with the value element (it basically looks the same).

 

The error I get here looks like this:

 

trentbooks_1-1657305645177.png

 

OK, so it doesn't like me updating the Pipelines array with JSON. So how about using Select instead?

 

Attempt 2 - Select

So I figure maybe I can use Select on one of the specific elements of the array, like this:

 

trentbooks_2-1657305856982.png

 

Here, the From input has one of the elements of the Pipelines array (again, whichever one is the matching pipeline_id).

I then try to add the count and value like I did above. But this results in the following error:

 

trentbooks_3-1657305950772.png

 

So this one chokes too, as it's looking for an Array and I'm trying to update JSON data within an array. What I anticipate here is that if I feed it the ENTIRE Pipelines variable, it's going to try to update every element within the array, and I don't want to do that.

 

So...how would I go about updating one single element of JSON data within an array of JSON objects?

 

Thanks very much for taking a look!

Categories:
  • AS-06081019-0 Profile Picture
    1,738 Super User 2024 Season 1 on at

    @trentbooks Could you please try using 'Append to Array' in variables. 

  • trentbooks Profile Picture
    18 on at

    Won't that create a new element in the Pipelines array? So I would have 6 Pipeline objects instead of 5, and two of them would share the same pipeline_id, right? Or am I misunderstanding how Append to Array would be used here?

  • AS-06081019-0 Profile Picture
    1,738 Super User 2024 Season 1 on at

    @trentbooks 

     

    Could you please try below, in your attempt 1(add the function createArray() that contain the setProperty() to keep the array type)

     

    setProperty(variables('Test'),'actions',setProperty(variables('Test')['actions'],'Initialize_variable',setProperty(variables('Test')['actions']['Initialize_variable'],'inputs',setProperty(variables('Test')['actions']['Initialize_variable']['inputs'],'variables', createArray(setProperty(variables('Test')['actions']['Initialize_variable']['inputs']['variables'][0],'value','Value2'))))))

  • trentbooks Profile Picture
    18 on at

    Thanks for the suggestion. It doesn't look like Append to Array is going to work because it won't allow self references, per the error message found here:

     

    trentbooks_0-1657310254638.png

     

  • Verified answer
    trentbooks Profile Picture
    18 on at

    I ended up just rebuilding the entire array via compose and restoring it. It's big, ugly, and hairy, but it works. 

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 307 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 289

#3
Henil Profile Picture

Henil 127

Last 30 days Overall leaderboard