mholt / PapaParse

Fast and powerful CSV (delimited text) parser that gracefully handles large files and malformed input
http://PapaParse.com
MIT License
12.55k stars 1.15k forks source link

Ignore unwanted fields for parsing #856

Closed magoarcano closed 3 years ago

magoarcano commented 3 years ago

When headers=true sometimes we don't want al the fields in the returned parsed items.

Now if headers line is: id, name, date, description I get the parsed items: [{id: "23", name: "John", date: "2021-01-01", description: "very long text I don't care"}, ...]

It would be nice to return just the fields we need, specially when there are many unwanted fields, the file is very big, or field values are very long.

Better to get: [{id: "23", name: "John", date: "2021-01-01"}, ...]

We could define the un/wanted fields in the transformHeader function, being ignored if it returns null. Or adding other parameters to the config: ignore (providing a list of the fields to ignore), and only (providing a list of fields to include only them)

pokoli commented 3 years ago

Thanks for your suggestion but I do not think we should implement that.

The objetive of PapaParse is just to parse the data and return all the parsed file. If you just need a subset of the information for each row is just a mather of filtering this data after the file is parsed.

If you can are about performance you can use streaming to filter the data.