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 / Length of an array wit...
Power Automate
Answered

Length of an array within JSON body/array

(0) ShareShare
ReportReport
Posted on by

Hello, 

 

I have an array that is coming from Parse JSON function. Within that parsed main body/array is another array called departments_ordered. Please would there be an easy way to obtain the number of objects/items within that array? See my current flow below

Ajwou_0-1631103022562.png

 

This actually links to a more general question - how can I "access" the individual items within an array- when using Expression?

 

Thank you, 

 

Ajwou

Categories:
I have the same question (0)
  • Verified answer
    Paulie78 Profile Picture
    8,422 Moderator on at

    You probably want:

    length(items('Apply_to_each')?['department_ordered'])

    If you stick that in a compose action within the loop, then you will be able to verify the output.

     

  • Pstork1 Profile Picture
    69,024 Most Valuable Professional on at

    @Paulie78 's suggestion will work inside the loop.  If you want to do it outside the loop based off the parse json it will be somethng like this:

    length(body('Parse_JSON')?['body/value']?['department_ordered'])

    The actual code will depend on the name of the root object and the path to the deparment_ordered array.

  • Ajwou Profile Picture
    on at

    Hi there, 

     

    Thank you for this. I tried including it in the Compose action (as expression), however it won't let me save the flow - looks like it doesn't like the source?

    Ajwou_0-1631106239616.png

     

  • Paulie78 Profile Picture
    8,422 Moderator on at

    That is because in your original screenshot you were in an apply/each loop, so I wrote the expression for that situation.

  • Ajwou Profile Picture
    on at

    Apologies for that. I should have included the full flow there from the start. 

     

    I have used the expression within loop for the condition field and got the following error

    Ajwou_0-1631107833887.png

    Essentially, I have list of projects where some of them will have multiple departments and I am trying to send projects with multiple departments to one list and projects with only one department to another. 

  • Ajwou Profile Picture
    on at

    @Pstork1 - I tried the expression outside the loop, within compose action, but the flow doesn't like it. 

    Ajwou_0-1631111173530.png

    The JSON schema used for parsing the data looks similar to the below:

    Ajwou_1-1631111510651.png

    Sorry if some things are not obvious to me. I currently started looking into JSON/data and all is completely new. 

  • Pstork1 Profile Picture
    69,024 Most Valuable Professional on at

    That would be because your root of the schema is an array, not an object.  You'll need to specify which array item you want to get the length of departments for.  You can do that by putting the compose inside an apply to each or by specifying the specific index that you want to check.  Something like this

    length(body('Parse_JSON')?['body/value'][0]?['department_ordered'])

    Which should show you the number of departments in the first item of the array.  This is dependent on what the first item in the array is actually called in the parse JSON.  It may not be Body/value.

  • Ajwou Profile Picture
    on at

    @Pstork1 - thank you for helping and patience. The parse JSON output starts with {"body":[{ and then continues in the same way as the JSON schema. The 'departments_ordered' is within the main (body) array (first level) and I am trying to get the number of items within that 'departments_ordered'. I tried putting the 

    length(body('Parse_JSON')?['body/value'][0]?['department_ordered'])

    Ajwou_1-1631178095341.png

     

    within the loop but that doesn't work. I always get the following error:

    Ajwou_2-1631178229755.png

    Even when I tried with defining the index

    Ajwou_3-1631178367800.png

    I get similar error

    Ajwou_4-1631178570081.png

     

     

     

     

     

     

  • Pstork1 Profile Picture
    69,024 Most Valuable Professional on at

    Try this.  Add a compose statement inside the Apply to each loop based on the body just before the condition that checks the length.  You'll actually need to add it after the condition and then drag the condition below it.  You can't add a new action to the top of a loop or drag one there.  In that condition add the dynamic content for current item.  Then send me a screenshot of the tooltip you get when you hover over that entry in the compose.  From that I'll be able to tell you what the exact length formula should look like.

  • Ajwou Profile Picture
    on at

    Thank you for the advise. I added one more condition and all went under Apply to each, then I check the tooltip as you suggested on Apply to each - department_ordered and used it as the condition - see below:

    Ajwou_0-1631200319512.png

    It seems to be delivering the required output now, but thought I would check with you if the condition makes sense. 

    Also wondering how would the expression look if I would want the length right afterer parsing (outside the Apply to each. This is the tooltip on the Body

    Ajwou_1-1631200579737.png

     

     

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 250 Super User 2026 Season 1

#2
Expiscornovus Profile Picture

Expiscornovus 222 Most Valuable Professional

#3
Haque Profile Picture

Haque 174

Last 30 days Overall leaderboard