web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Convert List of Lists ...
Power Automate
Answered

Convert List of Lists into a Data Table to Save CSV

(0) ShareShare
ReportReport
Posted on by 31
Hello!
 
I have an Office Script that extracts and transforms data from an Excel file into a list of lists that I'm eventually trying to write into a SQL Server table, with the thought of using the Write to CSV action to stage the data in a CSV and then write it to SQL Server.
 
My flow below gets a list of Excel files of various types (xlsx, xlsb, xlsm) from a SharePoint folder, extracts the data from one of the worksheets from each file and transforms it into a normalized list of data via an Office Script.  The challenge is that while the script quickly and efficiently returns the needed data, it returns it as a list of lists and that's where I get stuck in trying to parse it into a data table.
 
Here's what the flow looks like before adding a Write to CSV action:
 
I get either an error or objects output as opposed to rows & columns when I put a Write to CSV action after the Run Script action because Run Script returns a list of lists, as follows:
 
I can't seem to figure out a good way to parse this list of lists into a data table to save it appropriately to any file type, other than using a "For Each" to add it to a new list, but with 9,518 items per import file it would take weeks at best to extract this data from all the import files.
 
My thought was to use a Write to CSV action to dump these lists into a file I could then easily import into SQL Server and then just re-write that file on each pass of the loop, but the CSV file only outputs the list objects as the only row of data:
 
Is there a way to parse that nested list to get the CSV output to write the data within each list as opposed to writing 9,518 columns of System.Collections.Generic.List'1[System.Object] as the response?
 
Thanks so much for your help!
I have the same question (0)
  • stampcoin Profile Picture
    5,058 Super User 2025 Season 2 on at
     
    Can you change the script to generate array for you flow ? if you'd like this way.
    Use Python will be much more easier if you only take data from excel and import in SQL Server.
     
  • LC-21041801-0 Profile Picture
    31 on at
    @stampcoin, thank you, yes, I've updated the script to return JSON format, but I can't seem to convert it to a custom object as I'm getting "additional text encountered after reading JSON object" when trying to use the "JSON to Custom Object" action.
     
    Here's what the new output from the script looks like:
     
    I added a variable called "ImportedSTLYJSON" using Set Variable, and it seems to parse the objects and items out correctly, but I can't parse it into a custom object to save as CSV or pass directly over to SQL Server.
     
    Here's what the variable output looks like:
     
    And when drilling-down to individual items, it looks like the properties are correctly returning:
     
    However, when trying to convert it to custom object, it keeps giving me the "encountered additional text" error.  Is there a better way to load this to a data table or similar object to avoid this error?
     
    Thanks for your help!
     
    Lance
  • stampcoin Profile Picture
    5,058 Super User 2025 Season 2 on at
     
    I did some test, you could have it as reference if you like. hope this help you a little bit.
     
     
     
  • Verified answer
    LC-21041801-0 Profile Picture
    31 on at
    Got the complicated stuff right, missed the part where I needed to stringify the JSON, that took care of it.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard