PapaParse
PapaParse copied to clipboard
Add the ability to define columns when the file has no header
As a workaround I'm having to parse, unparse and parse again in order to read a file with no headers and get an array of objects:
Papa.parse(file, {
complete: result => {
let contentWithHeader = Papa.unparse({
fields: ['column1', 'column2', 'column3'],
data: result.data
});
let newResult = Papa.parse(contentWithHeader, {
header: true
});
console.log(newResult);
}
});
File:
valueA;valueB;valueC
valueD;valueE;valueF
...
Result:
data: [{
column1: "valueA"
column2: "valueB"
column3: "valueC"
}, {
column1: "valueD"
column2: "valueE"
column3: "valueF"
}, ...
]
I could also append the headers to the file, but I'd have to read it first and I don't think that would be good for performance neither.
Makes sense for me. It iwll be great if you can fill a PR implementing it
a 'fields' configuration option may receive an array of column names that would override the first line originating headers, if they exist.