1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Node.jsでcsvからjson変換

Posted at

0.作業フォルダ
 C:\tmp\c2j

1.インストーラーのダウンロード
 http://nodejs.org/

2.csvtojson をインストール
 npm install csvtojson

3.スクリプト
 c2j.js
//引数確認
/*
for(var i = 0;i < process.argv.length; i++){
console.log("argv[" + i + "] = " + process.argv[i]);
}
*/

var fs = require('fs');
var Converter=require("csvtojson").Converter;
var csvConverter = new Converter({
  constructResult: false,
  toArrayString: true
});

var readStream = fs.createReadStream(process.argv[2]);
var writeStream = fs.createWriteStream(process.argv[3]);

readStream.pipe(csvConverter).pipe(writeStream);
console.log("END");

4.実行
 cd C:\tmp\c2j
 node c2j.js test.csv test.json

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?