← All tools

csvwriter

Popularity 65 Updated Development & Build

Create CSV from complex JSON objects with CLI or API

npmauto-collected

Installation

npm
npm install -g csvwriter

Install with npm.

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"}}' | csvwriter

Using files:

$ csvwriter -o converted.csv source.json

Features

  • 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)