Keyang / node-csvtojson

Blazing fast and Comprehensive CSV Parser for Node.JS / Browser / Command Line.
MIT License
2.02k stars 271 forks source link

Parser always give column value 0 if the previous record's column have a number in it. #132

Closed hadijaveed closed 7 years ago

hadijaveed commented 7 years ago

Sample CSV Records

ID  FIELDVALUE  TRANSLATIONVALUE
1   1   1 GB
2   2   2gig
3   4   4gig
4   8   8gig
5   AA  AA Batteries
6   AAA AAA Batteries

So if I console.log after every record is parsed I get following results

{ ID: 1, FIELDVALUE: 1, TRANSLATIONVALUE: '1 GB' }
{ ID: 2, FIELDVALUE: 0, TRANSLATIONVALUE: '2gig' }
{ ID: 3, FIELDVALUE: 0, TRANSLATIONVALUE: '4gig' }
{ ID: 4, FIELDVALUE: 0, TRANSLATIONVALUE: '8gig' }
{ ID: 5, FIELDVALUE: 0, TRANSLATIONVALUE: 'AA Batteries' }
{ ID: 6, FIELDVALUE: 0, TRANSLATIONVALUE: 'AAA Batteries' }

if I remove the numbers in FieldValue column parser gives me the right results.

ID  FIELDVALUE  TRANSLATIONVALUE
1   something   1 GB
2   something   2gig
3   something   4gig
4   something   8gig
5   AA  AA Batteries
6   AAA AAA Batteries

Results

{ ID: 1, FIELDVALUE: something, TRANSLATIONVALUE: '1 GB' }
{ ID: 2, FIELDVALUE: something, TRANSLATIONVALUE: '2gig' }
{ ID: 3, FIELDVALUE: something, TRANSLATIONVALUE: '4gig' }
{ ID: 4, FIELDVALUE: something, TRANSLATIONVALUE: '8gig' }
{ ID: 5, FIELDVALUE: AA, TRANSLATIONVALUE: 'AA Batteries' }
{ ID: 6, FIELDVALUE: AAA, TRANSLATIONVALUE: 'AAA Batteries' }

So can you suggest me the fix of this problem ?

Keyang commented 7 years ago

Hi, you can set checkType:false to stop type inferring

~Keyang

On 9 January 2017 at 21:55, hadi javeed notifications@github.com wrote:

Sample CSV Records

ID FIELDVALUE TRANSLATIONVALUE 1 1 1 GB 2 2 2gig 3 4 4gig 4 8 8gig 5 AA AA Batteries 6 AAA AAA Batteries

So if I console.log after every record is parsed I get following results

{ ID: 1, FIELDVALUE: 1, TRANSLATIONVALUE: '1 GB' } { ID: 2, FIELDVALUE: 0, TRANSLATIONVALUE: '2gig' } { ID: 3, FIELDVALUE: 0, TRANSLATIONVALUE: '4gig' } { ID: 4, FIELDVALUE: 0, TRANSLATIONVALUE: '8gig' } { ID: 5, FIELDVALUE: 0, TRANSLATIONVALUE: 'AA Batteries' } { ID: 6, FIELDVALUE: 0, TRANSLATIONVALUE: 'AAA Batteries' }

if I remove the numbers in FieldValue column parser gives me the right results.

ID FIELDVALUE TRANSLATIONVALUE 1 something 1 GB 2 something 2gig 3 something 4gig 4 something 8gig 5 AA AA Batteries 6 AAA AAA Batteries

Results

{ ID: 1, FIELDVALUE: something, TRANSLATIONVALUE: '1 GB' } { ID: 2, FIELDVALUE: something, TRANSLATIONVALUE: '2gig' } { ID: 3, FIELDVALUE: something, TRANSLATIONVALUE: '4gig' } { ID: 4, FIELDVALUE: something, TRANSLATIONVALUE: '8gig' } { ID: 5, FIELDVALUE: AA, TRANSLATIONVALUE: 'AA Batteries' } { ID: 6, FIELDVALUE: AAA, TRANSLATIONVALUE: 'AAA Batteries' }

So can you suggest me the fix of this problem ?

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Keyang/node-csvtojson/issues/132, or mute the thread https://github.com/notifications/unsubscribe-auth/ABCs9xwtC_ZE-WVuQJlisX0b3HWi5dF5ks5rQqzfgaJpZM4LexrN .

Keyang commented 7 years ago

If you are using CLI, just pass --checkType=false in command. This was performance improvement introduced in version 1.1.1

hadijaveed commented 7 years ago

Thank you very much for your quick response.