Skip to content

Incorrect parsing of wrapped values when the new line is right after the starting quote #240

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
4 of 5 tasks
symbianm opened this issue Oct 8, 2023 · 1 comment
Closed
4 of 5 tasks
Assignees
Labels
bug csv2json CSV to JSON

Comments

@symbianm
Copy link

symbianm commented Oct 8, 2023

Background Information

  • Module Version: 4.1.0
  • Node/Browser Version: node v18.17.1

The issue I'm reporting is with:

  • json2csv
  • csv2json

I have...

  • searched to see if an issue has already been reported.
  • verified that my JSON/CSV data is valid (using something like http://jsonlint.com or https://csvlint.io/).
  • tried upgrading to the latest version of json-2-csv (since the issue may already be fixed).

Expected Behavior

Quoted values split across multiple lines should be correctly parsed.

Actual Behavior

The parser behaves incorrectly when the new line is right after the starting quote.

Data Sample

CSV:

"User","Rental","City","State","ZipCode","Lead","Created","Qualified","Notes","Status","Details","Rating","Feedback","External Id"
"Leasing  Team","xxxxx North Sabre Drive","San Tan Valley","AZ","85142","AaronMiriam McAlpine","10/1/2023 5:25 PM MST","10/1/2023 5:27 PM MST","","Confirmed","10/1/2023 5:30 PM MST","5","
Layout was nice. Landscape needed work. But nice otherwise.","a001K00000vxWbxxxx"

Code Example

const fs = require('fs');
const { csv2json } = require('json-2-csv');

(async () => {
  const contentString = fs.readFileSync('test.csv');
  const jsonData = await csv2json(contentString.toString(), {
    parseValue: (fieldValue) => fieldValue, // stop converting values
  });
  console.log(jsonData);

  // Result
  // [
  //   {
  //     User: 'Leasing  Team',
  //     Rental: '34517 North Sabre Drive',
  //     City: 'San Tan Valley',
  //     State: 'AZ',
  //     ZipCode: '85142',
  //     Lead: 'AaronMiriam McAlpine',
  //     Created: '10/1/2023 5:25 PM USMST',
  //     Qualified: '10/1/2023 5:27 PM USMST',
  //     Notes: '',
  //     Status: 'Confirmed',
  //     Details: '10/1/2023 5:30 PM USMST',
  //     Rating: '5',
  //     Feedback: '',
  //     'External Id': undefined
  //   },
  //   {
  //     User: 'Layout was nice. Landscape needed work. But nice otherwise."',
  //     Rental: 'a001K00000vxWbFQAU',
  //     City: undefined,
  //     State: undefined,
  //     ZipCode: undefined,
  //     Lead: undefined,
  //     Created: undefined,
  //     Qualified: undefined,
  //     Notes: undefined,
  //     Status: undefined,
  //     Details: undefined,
  //     Rating: undefined,
  //     Feedback: undefined,
  //     'External Id': undefined
  //   }
  // ]
})();

test.csv
Screenshot 2023-10-08 at 9 59 27

mrodrig added a commit that referenced this issue Oct 29, 2023
… parse partial field

resolves the issue reported in #240
mrodrig added a commit that referenced this issue Oct 30, 2023
@mrodrig mrodrig mentioned this issue Oct 30, 2023
2 tasks
@mrodrig mrodrig self-assigned this Oct 30, 2023
@mrodrig mrodrig added bug csv2json CSV to JSON labels Oct 30, 2023
@mrodrig
Copy link
Owner

mrodrig commented Oct 30, 2023

Thanks for reporting this @symbianm! I can confirm that this was a bug that was present in the CSV parsing logic when an EOL delimiter (typically newline) appeared inside a field (typically quotes) delimited value. This issue is resolved now in version 5.0.1. Please let me know if you run into any other issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug csv2json CSV to JSON
Projects
None yet
Development

No branches or pull requests

2 participants