5

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)

Miha Šušteršič
  • 9,742
  • 25
  • 92
  • 163
  • 1
    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. – Lasse V. Karlsen Jan 03 '15 at 11:08
  • 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 dark – Miha Šušteršič Jan 03 '15 at 11:15
  • 1
    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. – Lasse V. Karlsen Jan 03 '15 at 11:18
  • 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" ] } } – Miha Šušteršič Jan 03 '15 at 11:45
  • You mean the result...? It seems there are no errors. – Lasse V. Karlsen Jan 03 '15 at 11:45
  • 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 help – Miha Šušteršič Jan 03 '15 at 11:59

2 Answers2

17

In your config, add

skipEmptyLines: true

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

apostl3pol
  • 874
  • 8
  • 15
Stéphane Laurent
  • 75,186
  • 15
  • 119
  • 225
0

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

Miha Šušteršič
  • 9,742
  • 25
  • 92
  • 163
  • 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. – Matt Jan 03 '15 at 16:50