node-csvtojson icon indicating copy to clipboard operation
node-csvtojson copied to clipboard

Using only `noheader: true` and `checkColumn: true` results in a `column_mismatched` parse error

Open jarod-f opened this issue 3 years ago • 0 comments

Hello!

I was using this library for something pretty specific, and ran into some curious (unintended?) behaviour.

Wondering if it is expected for a parse error to be thrown when noheader and checkColumn are both set to true?

I would expect that it would just 1) generate the default fieldN headers due to noheader: true and 2) use the number of columns in the 1st row to determine the base case for checkColumn.

  • Instead, a parse error is thrown, would this be considered a bug?

Here is a minimal, reproducable example:

Program

const csv = require('csvtojson');

const CSVTOJSON_PARAMETERS = {
  noheader: true,
  checkColumn: true,
};

const CSV_STRING = ' data0column0  , data0column1  , data0column2  ';

await csv(CSVTOJSON_PARAMETERS)
.fromString(CSV_STRING) 
.then((jsonData: Object[]) => {
  // ...
});

Expected Result

[{"field1": "data0column0", "field2": "data0column1", "field3": "data0column2"}]

Actual Result

CSV Parse Error: Error: column_mismatched. JSON Line number: 0

Thanks in advance for your time!

jarod-f avatar Oct 11 '22 07:10 jarod-f