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 / Parse JSON that someti...
Power Automate
Suggested Answer

Parse JSON that sometimes contain Array and sometime contain Object

(0) ShareShare
ReportReport
Posted on by 1,849 Season of Giving Solutions 2025
I have a Parse JSON action, with this schema:-
 
{
    "type""object",
    "properties": {
        "?xml": {
            "type""object",
            "properties": {
                "@@version": {
                    "type""string"
                },
                "@@encoding": {
                    "type""string"
                }
            }
        },
        "Envelope": {
            "type""object",
            "properties": {
                "@@xmlns:xsi": {
                    "type""string"
                },
                "@@xmlns:xsd": {
                    "type""string"
                },
                "@@xmlns:wsa": {
                    "type""string"
                },
                "@@xmlns:wsse": {
                    "type""string"
                },
                "@@xmlns:wsu": {
                    "type""string"
                },
                "@@xmlns:soap": {
                    "type""string"
                },
                "env:Header": {
                    "type""object",
                    "properties": {
                        "@@xmlns:env": {
                            "type""string"
                        },
                        "Action": {
                            "type""string"
                        },
                        "MessageID": {
                            "type""string"
                        },
                        "RelatesTo": {
                            "type""string"
                        },
                        "To": {
                            "type""string"
                        },
                        "Security": {
                            "type""object",
                            "properties": {
                                "wsu:Timestamp": {
                                    "type""object",
                                    "properties": {
                                        "@@wsu:Id": {
                                            "type""string"
                                        },
                                        "wsu:Created": {
                                            "type""string"
                                        },
                                        "wsu:Expires": {
                                            "type""string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                },
                "Body": {
                    "type""object",
                    "properties": {
                        "GetReportResultsResponse": {
                            "type""object",
                            "properties": {
                                "@@xmlns": {
                                    "type""string"
                                },
                                "GetReportResultsResult": {
                                    "type""object",
                                    "properties": {
                                        "ReportResults": {
                                            "type""object",
                                            "properties": {
                                                "@@reportId": {
                                                    "type""string"
                                                },
                                                "@@xmlns": {
                                                    "type""string"
                                                },
                                                "Result": {
                                                    "type""array",
                                                    "items": {
                                                        "type""object",
                                                        "properties": {
                                                            "LogType": {
                                                                "type""string"
                                                            },
                                                            "LogActor": {
                                                                "type""string"
                                                            },
                                                            "LogDate": {
                                                                "type""string"
                                                            },
                                                            "FirstAssignmentDistributionDate": {
                                                                "type""string"
                                                            },
                                                            "LogResult": {
                                                                "type""string"
                                                            },
                                                            "LogNote": {
                                                                "type""string"
                                                            },
                                                            "Id": {
                                                                "type""string"
                                                            }
                                                        },
                                                        "required": []
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
 
 
now most of the time the JSON will be in an array format for the Result, as follow, and the parse will workwell:-
 
 
but on rare occuations , the api will only have one item and the JSON will be as follow, for the Result:-
 
{
  "?xml": {
    "@version""1.0",
    "@encoding""utf-8"
  },
  "Envelope": {
    "@xmlns:xsi""http://www.w3.org/2001/XMLSchema-instance",
    "@xmlns:xsd""http://www.w3.org/2001/XMLSchema",
    "@xmlns:wsa""http://schemas.xmlsoap.org/ws/2004/08/addressing",
    "@xmlns:wsse""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd",
    "@xmlns:wsu""http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd",
    "@xmlns:soap""http://www.w3.org/2003/05/soap-envelope",
    "env:Header": {
      "@xmlns:env""http://www.w3.org/2003/05/soap-envelope",
      "Action""https://service.leads360.com/GetReportResultsResponse",
      "MessageID""urn:uuid:34b11f34-5caf-4507-99ac-155baba19712",
      "RelatesTo""urn:uuid:69f1ea3b-5e09-4981-9786-8cade0c10b20",
      "To""http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous",
      "Security": {
        "wsu:Timestamp": {
          "@wsu:Id""Timestamp-253ae2d9-90e6-445e-8978-182235698e22",
          "wsu:Created""2025-03-24T04:00:02.1548704Z",
          "wsu:Expires""2025-03-24T04:05:02.1548704Z"
        }
      }
    },
    "Body": {
      "GetReportResultsResponse": {
        "@xmlns""https://service.leads360.com",
        "GetReportResultsResult": {
          "ReportResults": {
            "@reportId""***",
            "@xmlns""",
            "Result": {
              "LogType""Status Change",
              "LogActor""Velocify System",
              "LogDate""2025-03-23T18:16:46",
              "LogResult""DNC",
              "LogNote""To: [DNC]",
              "Id""434,
              "FirstAssignmentDistributionDate""2025-03-23T18:18:49",
              "BrokerAssigned""**, ****"
            }
          }
        }
      }
    }
  }
}
 
where the Parse JSON action will raise this erorr:-
 
[
  {
    "message""Invalid type. Expected Array but got Object.",
    "lineNumber"0,
    "linePosition"0,
    "path""Envelope.Body.GetReportResultsResponse.GetReportResultsResult.ReportResults.Result",
    "schemaId""#/properties/Envelope/properties/Body/properties/GetReportResultsResponse/properties/GetReportResultsResult/properties/ReportResults/properties/Result",
    "errorType""type",
    "childErrors": []
  }
 
so how i can handle both formats in one action?
Thanks
Categories:
I have the same question (0)
  • Suggested answer
    MS.Ragavendar Profile Picture
    6,334 Super User 2026 Season 1 on at
     
    Your Parse JSON action expects Result to be an array, but sometimes the API returns a single object instead. This mismatch causes an error:
    "Invalid type. Expected Array but got Object."
    • Add a "Compose" action before the Parse JSON action.
    • Use this Expression in the Compose action:
    if(equals(type(variables('Result')), 'Array'), variables('Result'), createArray(variables('Result')))
    
    • In your Parse JSON action, replace Body() with the Output of the Compose action.
    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item
  • johnjohnPter Profile Picture
    1,849 Season of Giving Solutions 2025 on at
     
    I got this error, on the formula:-
     
    Unable
    to process template language expressions in action 'Compose' inputs at
    line '0' and column '0': 'The template function 'type' is not defined or
    not valid.'.
     
    any advice?

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
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard