← 全部工具

csvwriter

热度 65 更新于 开发与构建

Create CSV from complex JSON objects with CLI or API

npmauto-collected

安装

npm
npm install -g csvwriter

通过 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)