PapaParse icon indicating copy to clipboard operation
PapaParse copied to clipboard

unable to parse a 3 line with 14 column ; separated file with error: Too few fields: expected 14 fields but parsed 1

Open mschaaf opened this issue 2 years ago • 1 comments

We are using version 5.3.1. When we are trying to parse the attached file the error we get is Too few fields: expected 14 fields but parsed 1. If we put a further line into the file the library will be able to parse it again.

The config we use is

const parseConfig = {
    delimiter: '', // auto-detect
    newline: '', // auto-detect
    quoteChar: '"',
    escapeChar: '"',
    header: true,
    transformHeader: undefined,
    dynamicTyping: false,
    preview: 0,
    encoding: '',
    worker: false,
    comments: false,
    step: undefined,
    complete: undefined,
    error: undefined,
    download: false,
    downloadRequestHeaders: undefined,
    downloadRequestBody: undefined,
    skipEmptyLines: false,
    chunk: undefined,
    chunkSize: undefined,
    fastMode: undefined,
    beforeFirstChunk: undefined,
    withCredentials: undefined,
    transform: undefined,
    delimitersToGuess: [';', '\t', '|', ',', Papa.RECORD_SEP, Papa.UNIT_SEP],
};

The file which fails to parse: 1851.csv

Any help or fix would be appreciated.

mschaaf avatar Jun 01 '22 06:06 mschaaf

Hello @mschaaf ! 👋 I feel like the error you are getting is mainly related to the skipEmptyLines prop being turned off (false).

The error Too few fields: expected 14 fields but parsed 1 is mainly because when parsed, your data ends with this: image 🔼 you might notice the last element in the array being { 'ID': '' }. This is mainly because when you save a CSV on Excel, it adds an empty line at the end. You can see this if you open the CSV with your IDE: image

When using the parameters you outlined above and only changing skipEmptyLines to true , I am able to see your parsed data perfectly and without errors. image

Hope this helps!

mel-habip avatar Jun 04 '22 12:06 mel-habip