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 / JSON array object error
Power Automate
Answered

JSON array object error

(0) ShareShare
ReportReport
Posted on by 152

When I try to parse JSON I get an error "Invalid type. Expected Array but got Object." Is there something wrong with the JSON format?

 

 

{
 "type": "array",
 "properties": {
 "State": {
 "type": "string"
 },
 "Building": {
 "type": "string"
 },
 "Address": {
 "type": "string"
 },
 "City/State": {
 "type": "string"
 },
 "ZipCode": {
 "type": "integer"
 },
 "Floor": {
 "type": "string"
 },
 "Suite": {
 "type": "string"
 },
 "Area": {
 "type": "string"
 },
 "Location": {
 "type": "string"
 },
 "SerialNumber": {
 "type": "string"
 },
 "VendorID": {
 "type": "string"
 },
 "MfgName": {
 "type": "string"
 },
 "ModelName": {
 "type": "string"
 },
 "HostName": {
 "type": "string"
 },
 "Notes": {
 "type": "string"
 },
 "Black": {
 "type": "string"
 },
 "Cyan": {
 "type": "string"
 },
 "Magenta": {
 "type": "string"
 },
 "Yellow": {
 "type": "string"
 },
 "Tri": {
 "type": "string"
 },
 "Service": {
 "type": "string"
 },
 "Black": {
 "type": "string"
 },
 "Color": {
 "type": "string"
 }
 }
}

 

 

Categories:
I have the same question (0)
  • grantjenkins Profile Picture
    11,063 Moderator on at

    That JSON schema is expecting an array but looks like you're trying to pass in just an object. Are you able to show the actual data you're trying to parse?

  • Bill51106 Profile Picture
    152 on at

    It is from an office script I found online. I should probably ask, what is the correct way to get an Excel file into JSON from PA? Maybe I am going about this entirely wrong.

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Are you initially wanting to get your data from an Excel Table? If so, then you should be using List rows present in a table that will retrieve all the records and will already be in JSON format.

     

    grantjenkins_0-1669961287464.png

     

  • Bill51106 Profile Picture
    152 on at

    I have about 20K rows that it returns; I need to use JSON script. The connector is to slow and does not return all the values.

  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Ok, I've been playing around with the solution and got the following.

     

    I'm using the two tables below. One table (ColorsTable) contains the data I want to copy, and the other table (ColorsTableV2) will be where the rows will be copied.

     

    grantjenkins_0-1670055112159.png

     

    And using the Office Script below which is almost identical to the one you're using except I changed it to take in the worksheet name and table name. You would just need to setup the TableData interface to include your fields.

    function main(
     workbook: ExcelScript.Workbook,
     worksheetName: string,
     tableName: string): TableData[] {
     
     // Get the table in the specified worksheet.
     const table = workbook.getWorksheet(worksheetName).getTable(tableName);
    
     // Get all the values from the table as text.
     const texts = table.getRange().getTexts();
    
     // Create an array of JSON objects that match the row structure.
     let returnObjects: TableData[] = [];
     if (table.getRowCount() > 0) {
     returnObjects = returnObjectFromValues(texts);
     }
    
     // Log the information and return it for a Power Automate flow.
     console.log(JSON.stringify(returnObjects));
     return returnObjects;
    }
    
    // This function converts a 2D array of values into a generic JSON object.
    // In this case, we have defined the TableData object, but any similar interface would work.
    function returnObjectFromValues(values: string[][]): TableData[] {
     let objectArray: TableData[] = [];
     let objectKeys: string[] = [];
     for (let i = 0; i < values.length; i++) {
     if (i === 0) {
     objectKeys = values[i];
     continue;
     }
    
     let object = {};
     for (let j = 0; j < values[i].length; j++) {
     object[objectKeys[j]] = values[i][j];
     }
    
     objectArray.push(object as TableData);
     }
    
     return objectArray;
    }
    
    interface TableData {
     Name: string;
     Color: string;
     "Sign Off": string;
    }

     

    Below is the full flow. I'll go into each of the actions.

    grantjenkins_1-1670055348190.png

     

    Run script uses the script above, passing in the worksheet name and table name.

    grantjenkins_2-1670055388287.png

     

    Select adds my properties into an array so it's the correct format for the Graph API call to add the rows.

    grantjenkins_3-1670055433783.png

     

    Site and Add data to Excel (below) are using Invoke an HTTP request from Azure AD.

    grantjenkins_4-1670055613737.png

     

    Site uses the following Uri to get the id from the SharePoint site where my Excel file is located.

    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com:/sites/powerplatformtesting?$select=id

    grantjenkins_5-1670055916724.png

     

    Add data to Excel uses the following Uri including the id from the previous action.

    https://graph.microsoft.com/v1.0/sites/@{body('Site')?['id']}/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook/tables/ColorsTableV2/rows/add

     

    And the following Body:

    {
     "index": null,
     "values": @{body('Select')}
    }

     

    grantjenkins_8-1670057286167.png

     

    After running the flow, I get the following output.

    grantjenkins_7-1670056385896.png

     

    With 16 rows of data, it took approx. 6 seconds to complete.

    With 1000 rows of data, it took approx. 8 seconds to complete.

     

  • Bill51106 Profile Picture
    152 on at

    This is amazing, my only issue now is the final step when saving, I can't get the URL right. It keeps referencing "Correct to include a valid reference to "Site" for the input parameters of action Invoke an HTTP request 2"

     

    Thank you so much for all of your help!

  • grantjenkins Profile Picture
    11,063 Moderator on at

    If you can use the Graph Explorer, you can test what you have to try and isolate the issue. You'd need to sign in with your account.

     

    https://developer.microsoft.com/en-us/graph/graph-explorer

     

    I'd try the following first (with your site details) to ensure it's returning your site and the id. Note that the id will come back with three parts to it, separated by commas.

    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com:/sites/powerplatformtesting?$select=id

     

    The result should be something like the following:

    {
     "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(id)/$entity",
     "id": "happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a"
    }

     

    Then copy/paste the id of your site into the following Uri and test each of these to ensure it's returning data. And your Workbook and Table name.

    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook
    
    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook/tables
    
    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook/tables/ColorsTableV2
    
    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook/tables/ColorsTableV2/rows

     

  • Bill51106 Profile Picture
    152 on at

    I am getting there, slowly, but getting there! (Sometimes too slowly)

     

    I am familiar with graph explorer.

    Site and ID are turning as expected, exactly as specified. It has something to do with the final URI, trying to see how it gets put together, it doesn't seem quite right as of now, I think?

  • Bill51106 Profile Picture
    152 on at

    Still working on this.

     

    Having problems, all 3 parts come back exactly as specified with commas. I suspect it has something to do with lists. With the limited experience I have had with MS graph I have not had to use lists before to access my files. Under Documents my WB is located at Documents/LocationFile7/States.xlsx Any tips? Thank you!

  • grantjenkins Profile Picture
    11,063 Moderator on at

    @Bill51106 Not exactly what you mean?

     

    If your Excel file is stored within a folder path under a library you should be able to just specify the path to the folder.

     

    Taking my previous Uri - the first one gets the Excel file from the root of the Documents library, and the second one gets the Excel file from within a folder called Bulk Upload within the Documents library.

     

    //Root of the Documents library
    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/ColorsSheet.xlsx:/workbook
    
    //Inside Bulk Upload folder in the Documents library
    https://graph.microsoft.com/v1.0/sites/happywolf.sharepoint.com,d8370b93-afa4-5c3c-81c1-62b1cc2e681f,69a75a23-bcb6-42c8-83b9-21651223990a/lists/Documents/drive/root:/Bulk Upload/ColorsSheet.xlsx:/workbook

     

    Hopefully this is what you were after. If not, let me know.

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 784

#2
Valantis Profile Picture

Valantis 589

#3
Haque Profile Picture

Haque 522

Last 30 days Overall leaderboard