It appears that the options delimiter: 'auto', and noheader: true are not compatible with each other - csvtojson seems to decide to use "," as the delimiter in this case instead of detecting it in the first data row.
Minimal example (checkColumn is set to true to highlight that data is not split as expected):
var Converter = require("csvtojson").Converter;
var test_converter = new Converter({
delimiter: 'auto',
headers: ['col1', 'col2'],
noheader: true,
checkColumn: true
});
var my_data = 'first_val\tsecond_val';
test_converter.fromString(my_data, function(err, result) {
console.log(err);
console.log(result);
});
It's possible to work around this by prepending a fake header row to the data, specifying headers in the configuration, and skipping the noheader option:
var Converter = require("csvtojson").Converter;
var test_converter = new Converter({
delimiter: 'auto',
headers: ['col1', 'col2'],
noheader: false,
checkColumn: true
});
var my_data = 'first_val\tsecond_val';
my_data = 'header_val1, header_val2\n' + my_data;
test_converter.fromString(my_data, function(err, result) {
console.log(err);
console.log(result);
});
The above produces the expected output of [ { col1: 'first_val', col2: 'second_val' } ].
It appears that the options
delimiter: 'auto'
, andnoheader: true
are not compatible with each other - csvtojson seems to decide to use "," as the delimiter in this case instead of detecting it in the first data row.Minimal example (checkColumn is set to true to highlight that data is not split as expected):
Output:
row_process, Error: column_mismatched. Data: first_val\tsecond_val. Row index: 0
It's possible to work around this by prepending a fake header row to the data, specifying headers in the configuration, and skipping the noheader option:
The above produces the expected output of
[ { col1: 'first_val', col2: 'second_val' } ]
.