I need to parse a CSV file to json (or array, still trying to search for the best method!),
How should I approach this problem?
I've been reading into data-grid, handsontable and papaParser, but I'm still very confused. I'm still kind of a beginner at javascript. It would be a big help if you could give me the big picture on the best way in how proceed with this, I'm sure I could troubleshoot the technical details on my own. Thanks in advance!
Handsontable does not allow you to use CSV as the datasource so you would need to parse it to JSON first using another library. Using JSON itself requires some additional setup - especially when you have a nested structure of data. Then you might need to use the columns option the specify objects for a given column.
Within the abilities of that grid, you can alter columns and those would be reflected in a new CSV file generated by the exportToFile plugin.
The exportToFile plugin allows you to set some values as the delimiter or ability to show/hide headers to keep the consistency with your input CSV structure.
Example
const exportPlugin = hot.getPlugin('exportFile');
button.addEventListener('click', () => {
exportPlugin.downloadFile('csv', {
bom: false,
columnDelimiter: ',',
columnHeaders: false,
exportHiddenColumns: true,
exportHiddenRows: true,
fileExtension: 'csv',
filename: 'Handsontable-CSV-file_[YYYY]-[MM]-[DD]',
mimeType: 'text/csv',
rowDelimiter: '\r\n',
rowHeaders: true
});
});