Problems parsing CSV with nested quotes,commas etc
lyricnz opened this issue · 2 comments
lyricnz commented
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
Will create test program
lyricnz commented
Rather than debugging a (probably bad) custom CSV writer, I switched to csv-stringify, and everything now works fine. Closing.