How can I create nested objects from a CSV line without renaming my CSV headers?
It seems like it should be possible to configure the nested object mapping using the existing header names initialization/configuration of csvtojson without renaming the source header row in the CSV input file.
@markericson Did you end up finding a solution to this? I'm looking for the same. I tried using on('headers', (headers) => headers.map(transformStuffHere)) but that doesn't appear to affect the actual headers used while processing.
Update - You can use the .preFileLine() hook to transform the headers you already have by checking for index === 0
https://github.com/Keyang/node-csvtojson?tab=readme-ov-file#csv-file-line-hook
However! This seems to be a little buggy. On a test file with just one row of headers and one row of data, I was seeing both lines logging an index of 0. Adding more rows to my CSV and the issue changed. Could absolutely be user error, but just in case be wary of it mutating your rows