Skip to content
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

Can't parse CSV with quoted values #1071

Open
edossantos-sipcaller opened this issue Oct 24, 2024 · 3 comments
Open

Can't parse CSV with quoted values #1071

edossantos-sipcaller opened this issue Oct 24, 2024 · 3 comments

Comments

@edossantos-sipcaller
Copy link

Hello,

I'm trying to parse the following CSV, which looks good to me (please tell me if I'm wrong):
"Mobile","First name","Surname","Email Address","Next Case Review","Ref","Accounts Team","Job Id","Identifer" "18035551000","John","Doe","[email protected]","1001","1","TEAM_1001","JOB_0001","1" "18035551001","Jane","","[email protected]","1002","2","TEAM_1002","JOB_0002","2" "18035551002","Peter","Smith","[email protected]","1003","3","TEAM_1003","JOB_0003","3" "18035551003","Clara","White","","1004","4","TEAM_1004","JOB_0004","4" "18035551004","Stefan","Robertson","[email protected]","1005","5","TEAM_1005","JOB_0005","5" "18035551005","Millie","Watson","[email protected]","","6","TEAM_1006","JOB_0006","6" "18035551006","","Bond","[email protected]","1007","7","","JOB_0007","7" "18035551007","Robert","Simpson","[email protected]","1008","8","TEAM_1008","JOB_0008","8" "18035551008","Laura","Rivera","[email protected]","1009","9","TEAM_1009","JOB_0009","9" "18035551009","Alex","","[email protected]","1010","10","TEAM_1010","JOB_0010","10" "18035551010","Maria","Walker","[email protected]","1011","11","TEAM_1011","JOB_0011","11" "18035551011","Fred","Stuart","[email protected]","1012","12","TEAM_1012","JOB_0012","12" "18035551012","Walter","Black","[email protected]","1013","13","TEAM_1013","JOB_0013","13"

This is the code I use to parse this CSV:
readString(csvContent, { worker: true, delimiter: ',', skipEmptyLines: true, complete: (results: any) => { // Some processing logic here } });

When I do this, I get the following error:
At line 13 (column 1365): Trailing quote on quoted field is malformed
At line 13 (column 1365): Quoted field unterminated

This works fine if I remove all the quotes.

Any idea?

@janisdd
Copy link
Contributor

janisdd commented Nov 1, 2024

Yes, when using quotes, remove the trailing space in each line (or at least in the last line).

When a field is enclosed in quotes, only the text in quotes is part of the field. However, if there is a space before or after the quotes, this can lead to problems.

@edossantos-sipcaller
Copy link
Author

Hello @janisdd,

Thanks for your feedback, however that's not the case here. Those spaces are added by the GitHub editor, but are not in the file, and the issue can be reproduced without any leading or trailing spaces. This is a screenshot of a text editor showing that there is no space at the end (the special character shown marks the new line):
image

I'm also attaching a CSV file that can be used to reproduce this.
DataCausingError.csv

Thanks for looking into this.

@janisdd
Copy link
Contributor

janisdd commented Nov 1, 2024

Maybe I'm doing something wrong, but when I paste the file content here https://www.papaparse.com/demo it works without errors?

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

2 participants