csvwriter
Convert any JSON string to CSV with support for nested objects, filtering, many different CSV variations, CLI, ...
There are already a lot of good json to csv modules in the wild and this one aggregates all the features of the other modules and adds many, many more.
csvkit json2csv commander JSONPath cli-table
Install
npm install csvwriter
Usage
API
var csvwriter = require('csvwriter');
var data = {
"name": "csvwriter",
"repository": {
"type": "git",
"url": "https://github.com/GazonkFoo/csvwriter"
}
};
csvwriter(data, function(err, csv) {
console.log(csv);
});With configuration parameters:
var csvwriter = require('csvwriter');
var data = [/*...*/];
csvwriter(data, {delimiter: ';', decimalSeparator: ','}, function(err, csv) {
console.log(csv);
});Command Line Interface
Read from stdin and write to stdout:
$ echo '{"name": "csvwriter", "repository": {"type": "git", "url": "https://github.com"}}' | csvwriterUsing files:
$ csvwriter -o converted.csv source.jsonFeatures
- Command Line Interface and API
- Handles complex objects and arrays with different schemas
- Filtering and traversing using JSONPath
- Automatic and fixed column list
- Optional header row
- Escape quoting characters with double quotes (can be disabled)