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 / Creating a new JSON ob...
Power Automate
Answered

Creating a new JSON object while parsing another

(0) ShareShare
ReportReport
Posted on by 169

I am processing a JSON object of orders. They can have between 1 and n orders to process. Each order has between 1 and n line items to read as well.

 

Here is a representative sample of the JSON:

 

{
 "orders": [
 {
 "id": "the order id",
 "number": 1,
 "created": "2023-06-02T18:13:52Z",
 "status": "new",
 "order_lines": [
 {
 "id": "orderline_id01",
 "sku": "Item SKU",
 "quantity": 3,
				},
 {
 "id": "orderline_id02",
 "sku": "Item SKU",
 "quantity": 2,
 }
 ],
 "currency": "USD",
 "net_total": 40.0,
 "gross_total": 40.0
 }
 ],
 "has_more": false
}

 

 

I have this working fine.. a For Each loop with a For Each nested inside of it.

 

As part of the processing, I have to return a sub-set of the data back to the API I'm using. To do so I have to build the new JSON as I iterate through the above For Each Loop. 

 

The JSON in question looks like:

 

{
 "dispatch": {
 "order_id": "the order id",
 "comments": "Order submitted and will be processed.",
 "dispatch_lines": [
 {"sku": "Item SKU", "quantity": 3},
 {"sku": "Item SKU", "quantity": 2}
 ]
 }
 }

 

 

Programmatically, this is simple.

 

My challenge is where I loop through the order lines, I get the SKU and quantity and am building the dispatch lines. I can't see how to iteratively add to a variable. I can append to text - and that is working but I end up with a blank line at the start of the text. I suspect I can remove that initial blank line and then create my object after the last loop of the order lines loop.

 

Am I missing a more elegant way to build that new JSON?

 

I hope I was reasonably clear.

 

Thanks.

I have the same question (0)
  • mwd86 Profile Picture
    100 on at

    create entries  in a Datatable and then convert the datatable to a json.(https://powerusers.microsoft.com/t5/Power-Automate-Desktop/Data-Table-to-JSON-object-in-PAD/td-p/1323354)

  • Verified answer
    mmonline Profile Picture
    169 on at

    Thanks... What I ended up doing is creating the JSON, trimming the variable, converting it to a custom object and then converting the custom object to JSON.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 1,027

#2
Valantis Profile Picture

Valantis 809

#3
Haque Profile Picture

Haque 645

Last 30 days Overall leaderboard