PapaParse Errors explanation
Asked Answered
L

2

6

I'm using papaParse to parse an CSV file into JSON for further use. Upon parsin it returns

"errors": [ { "type": "FieldMismatch", "code": "TooFewFields", "message": "Too few fields: expected 21 fields but parsed 1", "row": 14 } ], "meta": { "delimiter": ";", "linebreak": "\r\n", "aborted": false, "truncated": false, "fields": [ "Output in top 10 percentiles (%)", "Overall", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] } }

can somebody please explain to me what this means? I read trough the documentation on their webpage but still don't understand what is wrong

the CSV file I'm working with is this (http://www.topdeckandwreck.com/excel%20graphs/Sheet10.csv)

Lassalle answered 3/1, 2015 at 11:5 Comment(6)
Well, you did read the error message I assume? Clearly the parser doesn't manage to split the row into columns. You should check which delimiter it is using.Outrage
Could this be the problem with decimal numbers used in the data? After reading this I added delimiter: ";", into the code, and the error message is still the same. I also have header: true, dynamicTyping: true. sry first time I'm using this and kinda lost in the darkRazorbill
No, doubt that, you're using the correct delimiter it seems. Could it be because it's trying to parse the final empty line of text in the file? Try removing the final newline so that the file immediately ends at the end of the last line of data and see if that helps.Outrage
after removing the final empty line in notepad the error message is this: "errors": [], "meta": { "delimiter": ";", "linebreak": "\r\n", "aborted": false, "truncated": false, "fields": [ "Output in top 10 percentiles (%)", "Overall", "1996", "1997", "1998", "1999", "2000", "2001", "2002", "2003", "2004", "2005", "2006", "2007", "2008", "2009", "2010", "2011", "2012", "2013", "2014" ] } }Razorbill
You mean the result...? It seems there are no errors.Outrage
yes you are absolutely right, the thing I was looking at was "meta": I read through the documentation again and I Think I understand it now. Thanks for all the helpRazorbill
V
20

In your config, add

skipEmptyLines: true

Reference: http://papaparse.com/docs#config-details

Vestpocket answered 27/8, 2016 at 14:40 Comment(1)
Thank you. This fix 1 line config fixed the issue. awesome.Hemorrhoid
L
1

Solution was posted by Lasse V Karlsen in the comments, removing the last empty line in notepad so the CSV file contains only data removes the error

Lassalle answered 3/1, 2015 at 12:1 Comment(1)
Yep. This is because, when you enable header row, it's an error if a row doesn't have as many fields as the header - they should match 1-to-1 on every row. A blank row only has 1 field, so it's an error.Nomination

© 2022 - 2024 — McMap. All rights reserved.