csvjson
Simple CSV to JSON and JSON to CSV converter with stream support
for Node.js and Browser.
© Pradeep Mishra, Licensed under the MIT-LICENSE
Features
- CSV to JSON object
- CSV to schema JSON object
- CSV to array object
- CSV to column array object
- JSON object to CSV
- JSON array to CSV
- Stream support
Example usage
var csvjson = require('csvjson');
convert csv data to json object
var data = fs.readFileSync(path.join(__dirname, 'schema_sample2.csv'), { encoding : 'utf8'});
var options = {
delimiter : ',',
quote : '"'
};
csvjson.toObject(data, options);
convert csv data to schema json object
var data = fs.readFileSync(path.join(__dirname, 'schema_sample.csv'), { encoding : 'utf8'});
var options = {
delimiter : ',',
quote : '"'
};
csvjson.toSchemaObject(data, options)
convert csv data to array object
var data = fs.readFileSync(path.join(__dirname, 'sample.csv'), { encoding : 'utf8'});
var options = {
delimiter : ',',
quote : '"'
};
csvjson.toArray(data, options);
convert csv data to column array object
var data = fs.readFileSync(path.join(__dirname, 'sample.csv'), { encoding : 'utf8'});
var options = {
delimiter : ',',
quote : '"'
};
csvjson.toColumnArray(data, options);
convert json object to csv data
var data = fs.readFileSync(path.join(__dirname, 'jsoncsv.json'), { encoding : 'utf8'});
var options = {
delimiter : ",",
wrap : false
}
csvjson.toCSV(data, options);
convert csv to json using stream
var read = fs.createReadStream(path.join(__dirname, 'sample.csv'));
var write = fs.createWriteStream(path.join(__dirname, 'sample.json'));
var toObject = csvjson.stream.toObject();
var stringify = csvjson.stream.stringify();
read.pipe(toObject).pipe(stringify).pipe(write);
npm install csvjson --save