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 / How to flatten a neste...
Power Automate
Answered

How to flatten a nested JSON using Apply to each in Power Automate?

(0) ShareShare
ReportReport
Posted on by 123
Hi Everyone,
I have a JSON object that contains a header and a list of lines I want to flatten this data so that the output looks like the example below
I am using an HTTP action to get the JSON response from an API endpoint.
My question is  how can I use Apply to each or loop to flatten the header and line data into a single structure? at the end of the flow I want to have this output
 
ExpenseReportNumber: ER-000245
EmployeeId: EMP-1023
EmployeeName: John Smith
LegalEntity: USMF
ReportName: Business Trip to Berlin
Purpose: Client meetings and technical workshop
ReportDate: 2025-12-10
CurrencyCode: EUR
TotalAmount: 485.75
Status: Submitted


LineNumber: 1
ExpenseCategory: Hotel
TransactionDate: 2025-12-07
Description: Hotel accommodation – Berlin
Amount: 280

LineNumber: 2
ExpenseCategory: Meals
TransactionDate: 2025-12-08
Description: Client dinner
Amount: 95.75

LineNumber: 3
ExpenseCategory: Transportation
TransactionDate: 2025-12-09
Description: Taxi to client office
Amount: 110


the API response :
{
  "ExpenseReportHeader": {
    "ExpenseReportNumber": "ER-000245",
    "EmployeeId": "EMP-1023",
    "EmployeeName": "John Smith",
    "LegalEntity": "USMF",
    "ReportName": "Business Trip to Berlin",
    "Purpose": "Client meetings and technical workshop",
    "ReportDate": "2025-12-10",
    "CurrencyCode": "EUR",
    "TotalAmount": 485.75,
    "Status": "Submitted"
   


  },
  "ExpenseReportLines": [
    {
      "LineNumber": 1,
      "ExpenseCategory": "Hotel",
      "TransactionDate": "2025-12-07",
      "Description": "Hotel accommodation – Berlin",
      "Amount": 280,
      "CurrencyCode": "EUR",
      "SalesTaxAmount": 19.6,
      "MerchantName": "Berlin Central Hotel",
      "PaymentMethod": "CorporateCard",
      "ProjectId": "PRJ-001",
      "CostCenter": "IT-OPS",
      "ReceiptRequired": true
    },
    {
      "LineNumber": 2,
      "ExpenseCategory": "Meals",
      "TransactionDate": "2025-12-08",
      "Description": "Client dinner",
      "Amount": 95.75,
      "CurrencyCode": "EUR",
      "SalesTaxAmount": 7.25,
      "MerchantName": "City Grill Restaurant",
      "PaymentMethod": "CorporateCard",
      "ProjectId": "PRJ-001",
      "CostCenter": "IT-OPS",
      "ReceiptRequired": true
    },
    {
      "LineNumber": 3,
      "ExpenseCategory": "Transportation",
      "TransactionDate": "2025-12-09",
      "Description": "Taxi to client office",
      "Amount": 110,
      "CurrencyCode": "EUR",
      "SalesTaxAmount": 8.9,
      "MerchantName": "Berlin Taxi Service",
      "PaymentMethod": "Cash",
      "ProjectId": "PRJ-001",
      "CostCenter": "IT-OPS",
      "ReceiptRequired": false
    }
  ]
}

 
I have the same question (0)
  • Suggested answer
    Kalathiya Profile Picture
    1,985 Super User 2026 Season 1 on at

    You can use the Parse JSON action in Power Automate to flatten your data. In the Content field, pass the response body from your HTTP action. Then click on “Generate from sample” and upload your sample JSON schema from the API response.

    Once parsed, you can use an Apply to Each loop on the lines array. Inside the loop, combine the header fields with each line item to create a flattened structure

    📩 Need more help? Mention@Kalathiya anytime!
    ✔️ Don’t forget to Accept as Solution if this guidance worked for you.
    💛 Your Like motivates me to keep helping

  • Verified answer
    Ish S Profile Picture
    96 on at
    If you want to get that output then below is a sample flow to get that output. Also below is the schema parse json:
     
     
    Parse schema:
    {
        "type""object",
        "properties": {
            "ExpenseReportHeader": {
                "type""object",
                "properties": {
                    "ExpenseReportNumber": {
                        "type""string"
                    },
                    "EmployeeId": {
                        "type""string"
                    },
                    "EmployeeName": {
                        "type""string"
                    },
                    "LegalEntity": {
                        "type""string"
                    },
                    "ReportName": {
                        "type""string"
                    },
                    "Purpose": {
                        "type""string"
                    },
                    "ReportDate": {
                        "type""string"
                    },
                    "CurrencyCode": {
                        "type""string"
                    },
                    "TotalAmount": {
                        "type""number"
                    },
                    "Status": {
                        "type""string"
                    }
                }
            },
            "ExpenseReportLines": {
                "type""array",
                "items": {
                    "type""object",
                    "properties": {
                        "LineNumber": {
                            "type""integer"
                        },
                        "ExpenseCategory": {
                            "type""string"
                        },
                        "TransactionDate": {
                            "type""string"
                        },
                        "Description": {
                            "type""string"
                        },
                        "Amount": {
                            "type""number"
                        },
                        "CurrencyCode": {
                            "type""string"
                        },
                        "SalesTaxAmount": {
                            "type""number"
                        },
                        "MerchantName": {
                            "type""string"
                        },
                        "PaymentMethod": {
                            "type""string"
                        },
                        "ProjectId": {
                            "type""string"
                        },
                        "CostCenter": {
                            "type""string"
                        },
                        "ReceiptRequired": {
                            "type""boolean"
                        }
                    },
                    "required": [
                        "LineNumber",
                        "ExpenseCategory",
                        "TransactionDate",
                        "Description",
                        "Amount",
                        "CurrencyCode",
                        "SalesTaxAmount",
                        "MerchantName",
                        "PaymentMethod",
                        "ProjectId",
                        "CostCenter",
                        "ReceiptRequired"
                    ]
                }
            }
        }
    }
     
     
     
     
    If these suggestions help resolve your issue. Please consider marking the answer as such.

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 March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 889

#2
Valantis Profile Picture

Valantis 830

#3
Haque Profile Picture

Haque 505

Last 30 days Overall leaderboard