A comprehensive CSV to JSON conversion library for Node.js with streaming support, extensive customization, and high-performance parsing capabilities.
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Core CSV parsing functionality providing the primary factory function interface and comprehensive configuration system for converting CSV data to JSON format.
Creates a new Converter instance with optional parsing parameters and stream options.
/**
* Creates a new CSV to JSON converter with optional configuration
* @param param - Optional parsing parameters to customize CSV parsing behavior
* @param options - Optional Node.js Transform stream options
* @returns Converter instance for chaining parsing operations
*/
function csvtojson(
param?: Partial<CSVParseParam>,
options?: TransformOptions
): Converter;Usage Examples:
import csvtojson from "csvtojson";
// Default parsing
const converter = csvtojson();
// Custom delimiter
const converter = csvtojson({ delimiter: ";" });
// Multiple options
const converter = csvtojson({
delimiter: ",",
trim: true,
noheader: false,
checkType: true
});Access to main factory function and Converter class via properties.
/**
* Alias to the main csvtojson factory function
*/
csvtojson.csv: typeof csvtojson;
/**
* Direct access to the Converter class for advanced usage
*/
csvtojson.Converter: typeof Converter;Usage Examples:
import csvtojson from "csvtojson";
// Using csv alias
const converter1 = csvtojson.csv({ delimiter: ";" });
// Direct Converter class usage
const converter2 = new csvtojson.Converter({ trim: true });Essential parsing parameters that control CSV parsing behavior.
interface CSVParseParam {
/**
* Delimiter used for separating columns. Use "auto" for auto-detection,
* or provide array of potential delimiters like [",","|","$"]
* @default ","
*/
delimiter: string | string[];
/**
* Quote character for surrounding column content containing delimiters.
* Set to "off" to ignore all quotes
* @default '"'
*/
quote: string;
/**
* Trim spaces surrounding column content
* @default true
*/
trim: boolean;
/**
* Indicates CSV data has no header row and first row is data
* @default false
*/
noheader: boolean;
/**
* Array to specify headers of CSV data. Overrides CSV header row if noheader is false
* @default undefined
*/
headers?: string[];
/**
* Output format: "json" for JSON objects, "csv" for array format, "line" for raw lines
* @default "json"
*/
output: "json" | "csv" | "line";
}Usage Examples:
// Auto-detect delimiter
const converter = csvtojson({
delimiter: "auto"
});
// Multiple potential delimiters
const converter = csvtojson({
delimiter: [",", ";", "|", "\t"]
});
// Custom headers for headerless CSV
const converter = csvtojson({
noheader: true,
headers: ["id", "name", "email", "age"]
});
// Different output formats
const csvArray = await csvtojson({ output: "csv" })
.fromString("1,2,3\n4,5,6");
// Result: [["1","2","3"], ["4","5","6"]]
const lineArray = await csvtojson({ output: "line" })
.fromString("1,2,3\n4,5,6");
// Result: ["1,2,3", "4,5,6"]Automatic type detection and conversion capabilities.
interface CSVParseParam {
/**
* Turn on field type checking and conversion
* @default false
*/
checkType: boolean;
/**
* Convert string "null" to null object in JSON outputs
* @default false
*/
nullObject: boolean;
/**
* Ignore empty values in CSV columns
* @default false
*/
ignoreEmpty: boolean;
}Usage Examples:
// Enable type detection
const converter = csvtojson({
checkType: true,
nullObject: true
});
const result = await converter.fromString('name,age,active\nAlice,25,true\nBob,null,false');
// Result: [
// { name: "Alice", age: 25, active: true },
// { name: "Bob", age: null, active: false }
// ]Options to control parsing performance and memory usage for large files.
interface CSVParseParam {
/**
* Maximum character count a CSV row can have. 0 means infinite.
* Prevents memory issues with corrupted data
* @default 0
*/
maxRowLength: number;
/**
* Check if column count matches header count
* @default false
*/
checkColumn: boolean;
/**
* Always interpret each line as a row, preventing inline line breaks
* @default false
*/
alwaysSplitAtEOL: boolean;
}Usage Examples:
// Limit row length for safety
const converter = csvtojson({
maxRowLength: 65535,
checkColumn: true
});Install with Tessl CLI
npx tessl i tessl/npm-csvtojson