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

Community site session details

Session Id :
Power Automate - Building Flows
Unanswered

Is this the correct way to get the first element in an array from parseJSON?

(0) ShareShare
ReportReport
Posted on by 375

Hi

I am pulling information from O365 and inserting it into a SharePoint Online list.

It works fine.

 

I now wish to check is users have "Unlicensed" in their "Licenses" property.

 

I have a parseJSON step which works for strings and will create the item in the list with all the properties.

But if I try to do this

body('Parse_JSON')?['assignedLicenses'][0]

for the licenses property then nothing seems to get created in the list.

It just runs and does nothing.

 

Thanks

P

 

pmwhelan_0-1677664344620.png

 

pmwhelan_1-1677664433643.png

 

pmwhelan_2-1677664537734.png

 

 

I have the same question (0)
  • pmwhelan Profile Picture
    375 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    This is what i mean by "it runs and does nothing"

     

    pmwhelan_0-1677665438665.png

     

  • Unknown geen idee Profile Picture
    1,757 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Dear pmwhelan,

     

    Did you look into using the expression 'first()' to get the first array element?

    This may help you.

    More information:

    https://manueltgomes.com/reference/powerautomate-function-reference/power-automate-first-function/

     

    Please note, the syntax is a bit funny (it threw me off at the start .. but eventually you will get it).

    Happy flowing, hope it helps,

    Koen

     

     

     

  • pmwhelan Profile Picture
    375 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Finally got an error

    Unable to process template language expressions in action 'Create_item' inputs at line '0' and column '0': 'The template language expression 'body('Parse_JSON')?['assignedLicenses'][0]' cannot be evaluated because property '0' cannot be selected. Please see https://aka.ms/logicexpressions for usage details.'.

  • pmwhelan Profile Picture
    375 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Hi Koen

    When I try 

    first(body('Parse_JSON')?['assignedLicenses'])
    I get...

    One or more fields provided is of type 'Null', a different type is expected.

  • Unknown geen idee Profile Picture
    1,757 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Dear Pmwhelan,

     

    Please view below an example of a correct syntax to grab an element out of the first entry in an array.

    Check the syntax carefully. It seems to me you have not defined it correctly.

     

    • first(outputs('Lists_items_present_in_table_-_SO_9')?['body/value'])?['ProductName']
    • first(Array)?['element']
    Happy flowing,
    Koen

     

  • Unknown geen idee Profile Picture
    1,757 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    I just pasted an example of a correct syntax in the reply: 

    first(outputs('Lists_items_present_in_table_-_SO_9')?['body/value'])?['ProductName']
  • pmwhelan Profile Picture
    375 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Thanks.

    I'm not sure how I apply that to a JSON value though?

    This looks wrong?

    first(body('Parse_JSON')?['assignedLicenses'])?['assignedLicenses']

    but what should the second assignedLicenses be?

    thanks

  • Unknown geen idee Profile Picture
    1,757 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Dear Pmwhelan,

     

    I assumed that the output from the 'Parse Json' action is an array, ... it is not an action I have used often. I have done some research and am now not so sure that the output is an array. If not, then the sugggested first() would not work.

     

    If it is however an array, I would expect the syntax to be something like:

    • first(body/value('Parse_JSON'))?['assignedLicenses']
    • first(body('Parse_JSON'))?['assignedLicenses']
  • grantjenkins Profile Picture
    11,059 Moderator on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    Are you able to show the output from your Compose action and Parse JSON action? If you click on the Code icon on the toolbar </> and paste it in the code editor, then we can look to see exactly what you need.

  • pmwhelan Profile Picture
    375 on at
    Re: Is this the correct way to get the first element in an array from parseJSON?

    When I go into that specific run of my flow that part is greyed out!

    Can that be fixed?

     

    pmwhelan_0-1677684304659.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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 659 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 386 Moderator

#3
chiaraalina Profile Picture

chiaraalina 290

Last 30 days Overall leaderboard