Skip to content

Troubleshooting

Current version: 3.1.0

This guide lists common JTCSV issues and practical fixes.

Quick triage

  1. Confirm the input format (CSV vs JSON).
  2. Confirm the delimiter (comma, semicolon, tab, pipe).
  3. Check if the file is large (prefer streaming when >10MB).
  4. Check the first line for headers.
  5. Re-run with onError: 'warn' and capture the line number.

Decision tree (mermaid)

mermaid
flowchart TD
  A[Error or unexpected output] --> B{CSV or JSON input?}
  B -->|CSV| C{Do you know the delimiter?}
  B -->|JSON| J[Use jsonToCsv or createJsonToCsvStream]
  C -->|Yes| D[Set delimiter explicitly]
  C -->|No| E[Enable autoDetect or set candidates]
  D --> F{Headers present?}
  E --> F
  F -->|Yes| G[hasHeaders: true]
  F -->|No| H[hasHeaders: false]
  G --> I{Large file?}
  H --> I
  I -->|Yes| K[Use createCsvFileToJsonStream or csvToJsonStream]
  I -->|No| L[Use csvToJson]

Common errors and fixes (20+)

Error or symptomLikely causeFixExample
Parsing error: wrong columnsDelimiter mismatchSet delimiter explicitlycsvToJson(csv, { delimiter: ';' })
Field count mismatchRow has extra separatorsFix input or set correct delimitercsvToJson(csv, { delimiter: ',' })
Unclosed quotesQuotes not balancedFix CSV quoting or escape quotes"a,""b"""
Empty outputhasHeaders wrongSet hasHeaders: false for headerless CSVcsvToJson(csv, { hasHeaders: false })
First row missinghasHeaders true but no headersSet hasHeaders: falsecsvToJson(csv, { hasHeaders: false })
Wrong header namesNeeds renamingUse renameMapcsvToJson(csv, { renameMap: { old: 'new' } })
Unexpected nullstrim + empty cellsSet trim: false or adjust datacsvToJson(csv, { trim: false })
Booleans as stringsparseBooleans offEnable boolean parsingcsvToJson(csv, { parseBooleans: true })
Numbers as stringsparseNumbers offEnable number parsingcsvToJson(csv, { parseNumbers: true })
Delimiter auto-detect wrongSimilar counts in first lineProvide delimiter or candidatescsvToJson(csv, { candidates: [';', ','] })
Large file is slowIn-memory parseSwitch to streamingcreateCsvFileToJsonStream('big.csv')
Memory limit errormemoryLimit too lowIncrease limit or streamcsvToJson(csv, { memoryLimit: Infinity })
Max rows exceededmaxRows too lowIncrease maxRowscsvToJson(csv, { maxRows: 2_000_000 })
Security error (CSV injection)Formula-like cellsKeep protection or escape datapreventCsvInjection: true
Invalid delimiter errorMulti-char delimiterUse a single character`delimiter: '
File not foundBad path or permissionsCheck path and accessreadCsvAsJson('data.csv')
Invalid file extensioncreateCsvFileToJsonStream requires .csvRename or use string APIcreateCsvFileToJsonStream('data.csv')
Schema validation failsSchema mismatchUpdate schema or inputcsvToJson(csv, { schema })
Transform errorCustom transform throwsFix transform or add try/catchtransform: (row) => ({ ...row })
Browser file parse failsNot using browser entryUse jtcsv/browserimport { parseCsvFile } from 'jtcsv/browser'
Worker helpers not availableMissing worker buildUse non-worker pathparseCsvFile(file)
NDJSON expectedOutput format confusionUse NDJSON helpersnpx jtcsv csv-to-ndjson data.csv --stream
UTF-8 BOM issuesBOM presentUse BOM stripping utilitiesautoDetectDelimiter or normalize input
Stream output is objectsStreaming returns rowsCollect or process row-by-rowfor await (const row of stream)

Debugging strategies

  • Add row-level logging:
javascript
const rows = csvToJson(csv, {
  onError: 'warn',
  errorHandler: (error, line, lineNumber) => {
    console.warn('bad row', lineNumber, error.message, line);
  }
});
  • Force delimiter to validate assumptions.
  • Re-run with hasHeaders: false to isolate header problems.
  • Reduce data to 5-10 lines and confirm behavior.

Performance troubleshooting

  • Use streaming for large files:
javascript
const stream = await createCsvFileToJsonStream('large.csv');
for await (const row of stream) {
  // process rows
}
  • Prefer fastPathMode: 'compact' if memory is tight.
  • Avoid converting huge CSV strings in memory.

When to open an issue

Include:

  • Input sample (10-20 lines)
  • Your options object
  • Node.js version and OS
  • Expected vs actual output

Released under the MIT License.