Template for converting large CSV files to JSON, then sending the data to a table or list.
This get data for CSV works even if there are commas in the CSV data. The only requirement is the the CSV file must follow the standard of placing double quotes “ , “ around any item eith in-data commas.
Set Up
Go to the bottom of this post & download the CSVToJSON_1_0_0_xx.zip file. Go to the Power Apps home page (https://make.powerapps.com/). Select Solutions on the left-side menu, select Import solution, Browse your files & select the CSVToJSON_1_0_0_xx.zip file you just downloaded. Then select Next & follow the menu prompts to apply or create the required connections for the solution flows.
Find the CSV To JSON solution in the list of solutions. Select it. Then find the CSV To JSON flow inside the solution package.
Once in the flow, go to the Get file content action & select the CSV you want to work with. Alternatively you could use a different action to get the CSV content as text.
After selecting your CSV, go to the Compose CSV data + Set-up action. If you used a different action to get the CSV file content as text, then you will need to input the output of that action in the CSV_Data parameter value (The get file content action you use may return the CSV file as base64, in which case you must use a base64tostring( ) expression on it in the input.
Adjust the rest of the parameters for your file. For example if your CSV has extra lines at the header or footer of the sheet/file, then account for those in the HeaderRowsToSkip & FooterRowsToSkip.
After that, move down to the Select CSV to JSON action. Input the header column names on the left side of the mapping & use the expressions outputs('Compose_CSV_data_+_Set-up')['NewDelimiter'])?[INSERT COLUMN NUMBER HERE STARTING FROM 0] on the right side of the mapping to match up their values. For example in the preceding volunteer contacts CSV example, First Name was the 0 index column so its value expression is outputs('Compose_CSV_data_+_Set-up')['NewDelimiter'])?[0] and Email is the 3rd index column so its value expression outputs('Compose_CSV_data_+_Set-up')['NewDelimiter'])?[3]
After that, we need to get the JSON schema for the Parse JSON action. So go & run the flow once. Then in the flow run, go to the outputs of the Select CSV to JSON action & copy the JSON output there.
Go back to the flow editor, go to the Parse JSON action, select Use sample payload to generate schema, & paste the JSON output to the sample payload menu. Select Done.
Now your CSV columns should be available as dynamic content from the Parse JSON action & you can insert them wherever you need in the rest of your flow.
(If you can export as a semicolon, tab, or other delimited file, then you can probably just use a simpler method like Paul’s here: https://www.tachytelic.net/2021/02/power-automate-parse-csv/?amp)
For more information on the delimiter change piece, visit this previous post:
To make a flow to send any CSV data to a new Excel table with given CSV header names without any column mappings, check this template:
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-To-New-Excel-Table/m-p/1826096#M964
*Copying the template into an existing flow may create issues with expressions. You may need to copy the rest of your existing flow into the CSV template flow, then move the template scope where you need it.
CSV To JSON Version 3
(More minor fixes & additions.
I adjusted several expressions so it can now handle a few more scenarios with arrays in the CSV data. It should handle any array that doesn't include double quotes and any array that is all strings with double quotes, so ["String1", "String2", "String3"], but it will have issues if it is a mixed array with some double-quoted strings and some other values, for example ["String", 4, 03/05/2022, "String2"] won't work.
I also adjusted how the LineBreak setting is set-up so it now uses the /r/n for the LineBreak. I also provided this link in the flow so anyone can look up the right string for the decodeUriComponent expression(s) if they happen to have different LineBreak characters. This change also made it possible to differentiate between in-data line-breaks and CSV row line-breaks on the files I tested, so it should now replace the in-data line-breaks, like the multiple-choice fields some sites use, with semi-colons. That should make those records much easier to deal with & parse in later actions.
I also looked over a problem with in-data trailing commas. I added a line in the settings where anyone can toggle whether they want it to adjust for trailing OR leading commas in the data, it just can't handle both in one dataset. So if one column in one row has ",String1 String2" and another column in another row has "String 3 String4," then it will have errors.)
CSV To JSON Auto Columns Version 1
An additional flow version that automatically does the JSON key-value matching. Useful if you may have use-cases with dynamic CSV files that may change each time the flow is run.
If you have any trouble with the standard legacy flow import method, you can also try an alternate Power Apps Solution import method here: Re: CSV to Dataset - Page 8 - Power Platform Community (microsoft.com)
Thanks for any feedback,
Please subscribe to my YouTube channel (https://youtube.com/@tylerkolota?si=uEGKko1U8D29CJ86).
And reach out on LinkedIn (https://www.linkedin.com/in/kolota/) if you want to hire me to consult or build more custom Microsoft solutions for you.
watch?v=-P-RDQvNd4A
@chico,
Alright, I do have this other template for automating reports downloaded to Desktop flows. It uses the set-up I'm talking about where it integrates the CSV/data-table parsing right into the batch set-up's "GenerateSPData" action.
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Automate-Reports-From-External-Datasourc...
You will just want to get rid of the Parse JSON action and drag the Select CSV to JSON action to where the "GenerateSPData" action is in the batch create. Then you can copy all your column references from the CSV to JSON action over to the "GenerateSPData" action under the _metadata line (don't change the metadata line, it is essential for the batch action to work). After that change-out the rest of the batch create should do all the reformatting to then include the data in a batch call to SharePoint so SharePoint can do all the data processing & creation.
The one other thing to note about Batch actions is they do not fail if there is an error in the data & it doesn't get added to the list. They only fail if the entire API call to SharePoint fails. So if you check the bottom parts of that report automation flow, you will find additional actions & expressions I used to check the API response for any errors or failed row uploads.
could not be resolved by the model. When a model is available, each type name must resolve to a valid type
The rabbit hole is indeed deep.
I jumped in for the batch delete/create steps and lost a few hours on the unable to resolve model error above. Turns out its not a good idea to use " - " in your SP list name... lesson learned.
All steps are screaming fast now!
once again you were one step ahead as my next task is dealing with a system that does not email reports and only offer the ability to do a manual download.
so. tomorrow I'll start digging in to your desktop flow solution!
@chico Nice,
Fair warning on the Desktop Flow though. I’m using a virtual machine that my IT team set up to be always on & logged in. That way we could use the $40/month attended RPA license without any other add-ons and we could call on desktop flows on that virtual machine at any time.
https://powerautomate.microsoft.com/en-us/pricing/
You will either need to duplicate that virtual machine set-up, or have the desktop flow use your computer & ensure that your computer is on & logged in when the flow is scheduled to run.
I recently found this awesome method of building custom connectors & functions with C# code and John here created his own custom action for parsing a CSV.
http://johnliu.net/blog/2021/9/parse-csv-through-code-in-power-automate-custom-connection
https://docs.microsoft.com/en-us/connectors/custom-connectors/write-code
The only downside is these custom actions are not readily share-able without copying the code and creating one yourself, or going through the Microsoft certification process for your action. Also there are many edge cases you would probably need to handle before Microsoft would be willing to certify an official Parse CSV action. But if I or anyone else wants to continue from where I or John left off, then we could further build things out for edge cases in these custom actions & try for the action certification.
@chico
Looks like Paul did start with the batch Dataverse actions a few months ago with batch delete. However, there is a bit more set-up in Azure to run the Dataverse API calls.
https://www.tachytelic.net/2021/11/power-automate-bulk-delete-dataverse/?subscribe=success#subscribe...
I'll look into this more and see what I can do for batch create & batch update templates for Dataverse.
Version 3 Now Available
More minor fixes & additions.
I adjusted several expressions so it can now handle a few more scenarios with arrays in the CSV data. It should handle any array that doesn't include double quotes and any array that is all strings with double quotes, so ["String1", "String2", "String3"], but it will have issues if it is a mixed array with some double-quoted strings and some other values, for example ["String", 4, 03/05/2022, "String2"] won't work.
I also adjusted how the LineBreak setting is set-up so it now uses the /r/n for the LineBreak. I also provided this link in the flow so anyone can look up the right string for the decodeUriComponent expression(s) if they happen to have different LineBreak characters. This change also made it possible to differentiate between in-data line-breaks and CSV row line-breaks on the files I tested, so it should now replace the in-data line-breaks, like the multiple-choice fields some sites use, with semi-colons. That should make those records much easier to deal with & parse in later actions.
I also looked over a problem with in-data trailing commas. I added a line in the settings where anyone can toggle whether they want it to adjust for trailing OR leading commas in the data, it just can't handle both in one dataset. So if one column in one row has ",String1 String2" and another column in another row has "String 3 String4," then it will have errors.
Google Drive Link: https://drive.google.com/file/d/1X6BGhXWSnZtFgUK0v-5bHo7RuKSNjNtV/view?usp=sharing
For faster CSV uploads or transfers…
I’ve previously mentioned batch create & batch update actions for SharePoint
Batch Create: https://www.tachytelic.net/2021/06/power-automate-flow-batch-create-sharepoint-list-items/
Batch Update: https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Batch-Update-SharePoint-List-With-Extern...
But there is also an option to quickly convert batches of CSV data into Excel tables
https://www.tachytelic.net/2021/08/power-automate-export-to-excel/?amp
Hi @takolota ,
That's a Really Great help for conversion from csv to Json. I Have gone trough your Flow and Tested.
I got one Issue in testing your flow If some of the Fields are Null, Sometimes it will Not detect that Field.
Like in my CSV i have 40 fields null but your full will detect only 32 times as null and rest 8 times it will map next field to that json Object.
Can you assist me on this?
@DukoDragon
Thanks. I tested with both empty cells and with cells filled with "null", but I couldn't replicate that issue. Please share some pictures & any other description you can give.
However, my first thought would be to check if the records are being dropped at the Parse JSON action due to the required fields listed in the schema.
You may want to try removing any potentially null fields from the "required" array in the schema and see if that solves the problem.
Hi @takolota,
After Doing Some Analysis on My data And Flow I found that There is an Issue with Action ''Select Reformat file data, replace in-data commas"
split(trim(replace(concat(outputs('Compose_CSV_data_+_Set-up')['LineBreak'], replace(replace(outputs('Compose_CSV_data_+_Set-up')['CSV_Data'], ', "', ',"'), '","', '",,"')), concat(outputs('Compose_CSV_data_+_Set-up')['LineBreak'], '"'), concat(outputs('Compose_CSV_data_+_Set-up')['LineBreak'], ',"#_5#'))), outputs('Compose_CSV_data_+_Set-up')['LineBreak'])
My file is having 6 Columns 2 are Date and Rest are Currency.
This is the Screenshot when all the Field are filled After Processing above Expression .
When one of the date field is empty it is like below.
It Completely Ignore that there is another date field.
Please Check on this