Skip to content

Add the ability to define columns when the file has no header #949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
drmencos opened this issue Aug 12, 2022 · 2 comments
Open

Add the ability to define columns when the file has no header #949

drmencos opened this issue Aug 12, 2022 · 2 comments

Comments

@drmencos
Copy link

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.

@pokoli
Copy link
Collaborator

pokoli commented Aug 16, 2022

Makes sense for me. It iwll be great if you can fill a PR implementing it

@alexbodn
Copy link

a 'fields' configuration option may receive an array of column names that would override the first line originating headers, if they exist.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants