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
This actually links to a more general question - how can I "access" the individual items within an array- when using Expression?
Thank you,
Ajwou
@Paulie78 @Pstork1 Thank you for your help. The first suggestion from Paulie78 was correct, just needed to be placed in the right location, that took me some time to realise.
One more thing I was wondering - would there be a possibility to exclude certain department name in the syntax:
I would like to exclude "Internal" from the count - in this case ending up with length 1 instead of 2.
For inside the apply to each loop the condition with the length now looks like the right syntax. Glad its working
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:
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
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.
@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'])
within the loop but that doesn't work. I always get the following error:
Even when I tried with defining the index
I get similar error
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.
@Pstork1 - I tried the expression outside the loop, within compose action, but the flow doesn't like it.
The JSON schema used for parsing the data looks similar to the below:
Sorry if some things are not obvious to me. I currently started looking into JSON/data and all is completely new.
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
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.
That is because in your original screenshot you were in an apply/each loop, so I wrote the expression for that situation.
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?