adaltas / node-csv

Full featured CSV parser with simple api and tested against large datasets.
https://csv.js.org
MIT License
3.98k stars 263 forks source link

Problems parsing CSV with nested quotes,commas etc #429

Closed lyricnz closed 4 months ago

lyricnz commented 4 months ago

Describe the bug

A clear and concise description of what the bug is, the CSV package version you are using. With input:

TIME,ACCOUNT_ID,METADATA
2024-02-22T23:45:19.521Z,112233445566,{""tags"":{""category"":""workload""}}

Fails with

     Error: Invalid Opening Quote: a quote is found on field "METADATA" at line 2, value is "{"
      at Object.parse (node_modules/csv-parse/dist/cjs/sync.cjs:789:21)
      at parse (node_modules/csv-parse/dist/cjs/sync.cjs:1328:23)
...

It looks valid to me? The default value of "escape" is double-quote, and default value of "quote" is also double-quote.

To Reproduce

Code is

import { parse } from 'csv-parse/sync';
const records = parse(auditCsvText, { bom: true, columns: true });

with the input above

Additional context

Works fine until the nested data was added.

lyricnz commented 4 months ago

Will create test program

lyricnz commented 4 months ago

Rather than debugging a (probably bad) custom CSV writer, I switched to csv-stringify, and everything now works fine. Closing.