Skip to main content

Notifications

Community site session details
Power Automate - General Discussion
Answered

How to select a Dynamic Json Property name

Like (0) ShareShare
ReportReport
Posted on 31 Jan 2023 21:51:00 by 5

Hello all,

 

I have a json output that looks similar to the below:

[
{
"39c04006-00d0-11e8-9bea-0275d4b83f51": {

"user_name": "test2"
},
"3a24d728-00d0-11e8-8494-0275d4b83f51": {

"user_name": "test3"

}
}
]

the name of the property aka the GUID above can be dynamic and this object array can have 3 or more objects. How can I turn this into a proper array so I can select all "user_name" from the json object.

  • Verified answer
    Chriddle Profile Picture
    7,738 Super User 2025 Season 1 on 25 Mar 2024 at 08:28:55
    Re: How to select a Dynamic Json Property name

    Chriddle_0-1711355196242.png

    From:

    xpath(
     xml(
     json(
     concat(
     '{"Root":{"Item":',
     outputs('Compose'),
     '}}'
     )
     )
     ),
     '/Root/Item/*'
    )

    Map Id:

    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(		
    	xpath(
    		item(),
    		'name(/*)'
    	),
    	'_x0030_','0'),'_x0031_','1'),'_x0032_','2'),'_x0033_','3'),'_x0034_','4'),'_x0035_','5'),'_x0036_','6'),'_x0037_','7'),'_x0038_','8'),'_x0039_','9'
    )

    Map UserName:

    xpath(
    	item(),
    	'string(/*/*)'
    )

     

    Result:

    [
     {
     "Id": "39c04006-00d0-11e8-9bea-0275d4b83f51",
     "UserName": "test2"
     },
     {
     "Id": "3a24d728-00d0-11e8-8494-0275d4b83f51",
     "UserName": "test3"
     }
    ]
  • powerappsusercr Profile Picture
    2 on 22 Mar 2024 at 21:30:33
    Re: How to select a Dynamic Json Property name

    Hey Juan, im in the same situation. How did you accomplish that?

     

    Thanks

  • juanpowerapps91 Profile Picture
    5 on 01 Feb 2023 at 13:49:31
    Re: How to select a Dynamic Json Property name

    Thank you for the answer. Unfortunately that's not going to work as the object is not an array. All the answers seem to indicate that this is not possible using out of the box functions in power automate. To loop through json objects you will need to use a c# or java script to accomplish this

  • SudeepGhatakNZ Profile Picture
    14,318 Most Valuable Professional on 31 Jan 2023 at 23:45:42
    Re: How to select a Dynamic Json Property name

    @juanpowerapps91 ,

    You could retrieve the values using indexes instead of field names.

     

    outputs('Compose')[0]['user_name']

    outputs('Compose')[1]['user_name']

    outputs('Compose')[2]['user_name']

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

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Leaderboard > Power Automate - General Discussion

#1
stampcoin Profile Picture

stampcoin 23

#2
Pstork1 Profile Picture

Pstork1 22 Most Valuable Professional

#3
Gprior Profile Picture

Gprior 19

Overall leaderboard
Loading started
Loading started