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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / How to iterate over ne...
Power Automate
Unanswered

How to iterate over nested object and access token using Apply to Each

(1) ShareShare
ReportReport
Posted on by 12

Hi community,
I'm working with a JSON structure in Power Automate like this:

this given below json is my compose
===========================

{
  "animals": {
    "429defc8-5b05-4c3e-920d-0bb911a61345": {
      "token": "202506111213458574.jpg",
      "name": "camel",
      "date": "20250614"
    },
    "429defc8-5b05-4c3e-920d-0bb911a613451": {
      "token": "2025061112513458575.jpg",
      "name": "elephant",
      "date": "20250614"
    }
  }
}
 

I want to loop through each animal entry using "Apply to each" in Power Automate and access the properties like token, name, etc.

I tried using:
item()?['token']

But it doesn't return anything.

 

What’s the correct way to set up the loop and access the values like token inside the Apply to each?

 

Thanks in advance!

Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,441 Super User 2025 Season 2 on at
    Use XPath to create a list of all properties (token, name, and date) and create blocks of three.
    Then combine each of these chunks into an object.
    chunk(
    	xpath(
    		xml(outputs('Compose')),
    		'//animals/*/*'
    	), 3
    )
    union(
    	json(item()[0]),
    	json(item()[1]),
    	json(item()[2])	
    )
     
  • CU25060522-1 Profile Picture
    12 on at
    any other way?
  • Chriddle Profile Picture
    8,441 Super User 2025 Season 2 on at
    createArray(outputs('Compose').animals)
    split(
    	first(
    		split(
    			body('Create_CSV_table'),
    			decodeUriComponent('%0D%0A')
    		)
    	),
    	','
    )
     
    outputs('Compose').animals[item()]
     
     
  • eliotcole Profile Picture
    4,363 Moderator on at
    Hope that this helps put you on the path to where you need to be, but I am not sure it exactly answers what you want. :)
    {"nodeId":"Scope","serializedValue":{"type":"Scope","actions":{"AnimalsObjCNST":{"type":"ParseJson","inputs":{"content":{"animals":{"429defc8-5b05-4c3e-920d-0bb911a61345":{"token":"202506111213458574.jpg","name":"camel","date":"20250614"},"429defc8-5b05-4c3e-920d-0bb911a61451":{"token":"2025061112513458575.jpg","name":"elephant","date":"20250614"}}},"schema":{"title":"{Initial CNST}","type":"object","properties":{"animals":{"title":"{Animals}","type":"object","additionalProperties":{"type":"object","properties":{"token":{"title":"string","type":"string"},"name":{"title":"string","type":"string"},"date":{"title":"string","type":"string"}}}}}}}},"ConstantsAnimalsObjCNST":{"type":"ParseJson","description":"This action can be used to base further actions upon as everything is in one place.","inputs":{"content":{"AnimalsOrig":"@body('AnimalsObjCNST')?['animals']","AnimalsOrigArray":"@body('SelectStrangeBrewArrCNST')","AnimalsUniqueArray":"@union(\n  body('SelectStrangeBrewArrCNST'), \n  body('SelectStrangeBrewArrCNST')\n)","DatesUnique":"@union(\n  body('SelectDatesArrCNST'), \n  body('SelectDatesArrCNST')\n)","NamesUnique":"@union(\n  body('SelectNamesArrCNST'), \n  body('SelectNamesArrCNST')\n)","TokensUnique":"@union(\n  body('SelectTokensArrCNST'), \n  body('SelectTokensArrCNST')\n)"},"schema":{"title":"{CNST Animals}","type":"object","properties":{"AnimalsOrig":{"description":"The original data ...","title":"{AnimalsOrig}","type":"object","additionalProperties":{"type":"object","properties":{"token":{"title":"string","type":"string"},"name":{"title":"string","type":"string"},"date":{"title":"string","type":"string"}}}},"AnimalsOrigArray":{"description":"The original data in JSON Array format.","title":"[Original Data]","type":"array","items":{"title":"Animal (OrigData)","type":"object","properties":{"token":{"title":"Token","type":"string"},"name":{"title":"Name","type":"string"},"date":{"title":"Date","type":"string"}},"required":["token","name","date"]}},"AnimalsUniqueArray":{"description":"The original data in JSON Array format stripping out any duplicates.","title":"[Unique Data]","type":"array","items":{"title":"Animal (UniqueData)","type":"object","properties":{"token":{"title":"Token","type":"string"},"name":{"title":"Name","type":"string"},"date":{"title":"Date","type":"string"}},"required":["token","name","date"]}},"DatesUnique":{"description":"All the different dates from the original data in a SIMPLE JSON String Array format.","title":"[Dates (Unique)]","type":"array","items":{"title":"Date","type":"string"}},"NamesUnique":{"description":"All the different names from the original data in a SIMPLE JSON String Array format.","title":"[Names (Unique)]","type":"array","items":{"title":"Name","type":"string"}},"TokensUnique":{"description":"All the different tokens from the original data in a SIMPLE JSON String Array format.","title":"[Tokens (Unique)]","type":"array","items":{"title":"Token","type":"string"}}}}},"runAfter":{"SelectNamesArrCNST":["Succeeded"],"SelectDatesArrCNST":["Succeeded"],"SelectTokensArrCNST":["Succeeded"]}},"SelectTokensArrCNST":{"type":"Select","inputs":{"from":"@xpath(\n    xml(\n        addProperty(\n          json('{}'), \n          'r',\n          body('AnimalsObjCNST')\n        )\n    ), \n    '/r/animals/*'\n)","select":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/token']"},"runAfter":{"SelectStrangeBrewArrCNST":["Succeeded"]}},"SelectNamesArrCNST":{"type":"Select","inputs":{"from":"@xpath(\n    xml(\n        addProperty(\n          json('{}'), \n          'r',\n          body('AnimalsObjCNST')\n        )\n    ), \n    '/r/animals/*'\n)","select":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/name']"},"runAfter":{"SelectStrangeBrewArrCNST":["Succeeded"]}},"SelectDatesArrCNST":{"type":"Select","inputs":{"from":"@xpath(\n    xml(\n        addProperty(\n          json('{}'), \n          'r',\n          body('AnimalsObjCNST')\n        )\n    ), \n    '/r/animals/*'\n)","select":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/date']"},"runAfter":{"SelectStrangeBrewArrCNST":["Succeeded"]}},"SelectStrangeBrewArrCNST":{"type":"Select","description":"This is everything ","inputs":{"from":"@xpath(\n    xml(\n        addProperty(\n          json('{}'), \n          'r',\n          body('AnimalsObjCNST')\n        )\n    ), \n    '/r/animals/*'\n)","select":{"token":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/token']","name":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/name']","date":"@json(xml(concat('<animal>',join(reverse(skip(reverse(split(join(skip(split(decodeBase64(item()?['$content']), '>'), 1), '>'), '</')), 1)), '</'),'</animal>')))?['animal/date']"}},"runAfter":{"AnimalsObjCNST":["Succeeded"]}}},"runAfter":{}},"allConnectionData":{},"staticResults":{},"isScopeNode":true,"mslaNode":true}
    That code should be easily copied and pasted into a V3 designer (which I guess you're using) as an action ... if not, it's easily translatable to V2.
    In the V3 designer it should look a little like this:
     
    This will provide you with a 'ConstantsAnimalsObjCNST' that should give you a little bit of data that you can use to make more, or work with that.
     
    See if you can take some of the concepts that I have introduced, here, and run with them. 👍

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard