Current version: 3.1.0
Welcome to the jtcsv API documentation. This library provides complete JSON<->CSV bidirectional conversion with streaming support, security features, and TypeScript types.
npm install jtcsv
jsonToCsv() - Convert JSON array to CSV stringsaveAsCsv() - Save JSON as CSV filecreateJsonToCsvStream() - Streaming conversioncsvToJson() - Convert CSV string to JSON arrayreadCsvAsJson() - Read CSV file as JSONcsvToJsonIterator() - Async iterator for large filescreateCsvToJsonStream() - Streaming conversionjsonToNdjson(), ndjsonToJson(), parseNdjsonStream()jsonToTsv(), tsvToJson(), validateTsv()All streaming functions support backpressure and work with Node.js streams:
streamJsonToCsv() - Pipe JSON to CSVstreamCsvToJson() - Pipe CSV to JSONcreateNdjsonToCsvStream() - NDJSON to CSV transform stream=, +, -, @), enabled by default (preventCsvInjection: true)../ attacks, restricts to .csv/.json extensions onlyrfc4180Compliant: true)repairRowShifts: true)normalizeQuotes: true)jtcsv provides complete TypeScript definitions:
import {
jsonToCsv,
csvToJson,
JsonToCsvOptions,
CsvToJsonOptions
} from 'jtcsv';
const options: JsonToCsvOptions = {
delimiter: ',',
preventCsvInjection: true
};
const csv = jsonToCsv(data, options);
jtcsv provides specialized error classes for better error handling:
JtcsvError - Base error classValidationError - Invalid input dataSecurityError - Security violationsParsingError - CSV/JSON parsing failuresFileSystemError - File operation errorsLimitError - Exceeded limitsConfigurationError - Invalid optionsjtcsv is optimized for high performance:
csvToJson() – Convert CSV string to JSON arrayjsonToCsv() – Convert JSON array to CSV stringpreprocessData() – Flatten nested objects before conversiondeepUnwrap() – Internal utility for deep unwrappingreadCsvAsJson() – Read CSV file as JSON (async)readCsvAsJsonSync() – Synchronous file readingsaveAsCsv() – Save JSON data as CSV filesaveAsJson() – Save data as JSON filesaveAsJsonSync() – Synchronous JSON savecreateCsvToJsonStream() – Transform stream CSV→JSONcreateJsonToCsvStream() – Transform stream JSON→CSVstreamCsvToJson() – Pipe CSV stream to JSON streamstreamJsonToCsv() – Pipe JSON stream to CSV streamcreateCsvFileToJsonStream() – Stream CSV file to JSON objectscreateJsonReadableStream() – Create readable stream from JSON arraycreateCsvCollectorStream() – Collect CSV output into buffercreateJsonCollectorStream() – Collect JSON objects into arrayjsonToNdjson() – Convert JSON array to NDJSON stringndjsonToJson() – Parse NDJSON string to JSON arrayparseNdjsonStream() – Async iterator over NDJSON streamcreateNdjsonToCsvStream() – Transform NDJSON to CSVcreateCsvToNdjsonStream() – Transform CSV to NDJSONgetNdjsonStats() – Statistics about NDJSON datajsonToTsv() – Convert JSON array to TSV stringtsvToJson() – Parse TSV string to JSON arrayvalidateTsv() – Validate TSV structureisTsv() – Detect if string is likely TSVreadTsvAsJson() – Read TSV file as JSONreadTsvAsJsonSync() – Synchronous TSV file readingsaveAsTsv() – Save JSON as TSV filesaveAsTsvSync() – Synchronous TSV savecreateJsonToTsvStream() – Stream JSON to TSVcreateTsvToJsonStream() – Stream TSV to JSONJtcsvError, ValidationError, SecurityError, ParsingError, FileSystemError, LimitError, ConfigurationError – Specialized error classescreateErrorMessage() – Create detailed error messageshandleError() – Centralized error handlersafeExecute() – Safe execution wrapperautoDetectDelimiter() – Auto-detect CSV delimitervalidateFilePath() – Security validation for file pathsisEmail(), isUrl(), isDate() – Built-in validatorscreateBatchProcessor() – Batch processing helperasyncIterUtils – Utilities for async iterationdetectEncoding(), convertToUtf8() – Encoding utilitiesFor complete details, see the generated API documentation.
jtcsv works in browsers with Web Workers support:
import { jsonToCsv, csvToJson } from 'jtcsv/browser';
See the individual API documentation below for detailed usage information.