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 / append array of json w...
Power Automate
Unanswered

append array of json will mapping in select action

(0) ShareShare
ReportReport
Posted on by
Hi all.
we have array of object like 
[
{
"Qty": "225",
"_id": "659921c7d8df6256c4365004",
"item": "6599221f4069ad0deeffc462"
},
{
"Qty": "2100",
"_id": "659921c7d8df6256c4365004",
"item": "6599221f4069ad0deeffc461"
}
]
 
I need to map this array in select action like below mapping.
{
    "to": "_id",
    "variants":
                  [
                     { 
                        "variant": "Item"
                        "Qty""Qty"
                    }
                ],
  }
please if you have any idea share it with me thanks.
Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,713 Super User 2026 Season 2 on at

    Needs 2 Selects 😉

    Chriddle_1-1709115615276.png

     

    Data (Compose)

     

    [
    {
    "Qty": "225",
    "_id": "659921c7d8df6256c4365004",
    "item": "6599221f4069ad0deeffc462"
    },
    {
    "Qty": "2100",
    "_id": "659921c7d8df6256c4365004",
    "item": "6599221f4069ad0deeffc461"
    }
    ]

     

     

    DataEnhanced (Select)

    From

     

    outputs('Data')

     

    Map

     

    addProperty(
    	item(),
    	'variantsString',
    	concat(
    		'{"variant":"', item()['item'], '","Qty":"', item()['Qty'], '"}'
    	)
    )

     

     

    Select

    From

     

    union(
    	xpath(
    		xml(json(concat('{"Root":{"Item":', body('DataEnhanced'),'}}'))),
    		'//_id/text()'
    	),
    	json('[]')
    )

     

    Map to

     

    item()

     

    Map variants

     

    json(
    	concat(
    		'[',
    		join(
    			xpath(
    				xml(json(concat('{"Root":{"Item":', body('DataEnhanced'),'}}'))),
    				concat('//Item[_id="', item(), '"]/variantsString/text()')
    			),
    			','
    		),
    		']'
    	)
    )

     

     

    Result

     

    [
     {
     "to": "659921c7d8df6256c4365004",
     "variants": [
     {
     "variant": "6599221f4069ad0deeffc462",
     "Qty": "225"
     },
     {
     "variant": "6599221f4069ad0deeffc461",
     "Qty": "2100"
     }
     ]
     }
    ]

     

     

  • SamLed Profile Picture
    2,340 Moderator on at

    Hi @omargohar,

     

    You can do it this way, I added 2 objects with different ID to the test dataset you gave:

     

    SamLed_6-1709115647896.png

     

    1. Select IDs

    SamLed_1-1709114780868.png

     

    2. For each id, filter data matching current id :

    SamLed_2-1709114960403.png

    Apply to each from: union(body('Select_ID'),body('Select_ID')) (union ensure we get unique IDs)

     

    Filter:

    From: outputs('Data')

    Right condition operand: items('Apply_to_each')?['_id']

     

    3. Select and rename other object properties:

    SamLed_3-1709115267723.png

    From: body('Filter_array')

    Qty: item()?['Qty']

    Variant: item()?['item']

     

    4. Rebuild object

    SamLed_4-1709115409975.png

    to: items('Apply_to_each')?['_id']

    variants: body('Select')

     

    5. Finally, get array from apply to each:

    SamLed_5-1709115537818.png

     

    Results:

    SamLed_7-1709115696744.png

     

    Overall flow view:

    SamLed_8-1709115747523.png

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

     

     

     

     

     

     

     

  • SamLed Profile Picture
    2,340 Moderator on at

    Hi @Chriddle,

     

    Lol, you posted a few seconds before me, I like your design, can you improve it to deal with many different IDs without loop ? 

     

    Best regards,

    Sam

  • SamLed Profile Picture
    2,340 Moderator on at

    Hi @Chriddle@omargohar,

     

    @Chriddle: forget my previous question, it works with many IDs

    @omargohar: Take @Chriddle solution it is far the best one 😉

     

    Regards,

    Sam

  • Chriddle Profile Picture
    8,713 Super User 2026 Season 2 on at

    @SamLed This is already included 😉

  • SamLed Profile Picture
    2,340 Moderator on at

    @Chriddle  Yes, saw that, I tried giving a solution like yours, but failed due to my XPath low knowledges, you gave me the hints I lacked.  Many thanks 😉

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 272 Super User 2026 Season 2

#2
trice602 Profile Picture

trice602 147 Super User 2026 Season 2

#3
11manish Profile Picture

11manish 146 Super User 2026 Season 2

Last 30 days Overall leaderboard