-
Notifications
You must be signed in to change notification settings - Fork 0
/
LC2json2csv.js
33 lines (33 loc) · 991 Bytes
/
LC2json2csv.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
function JSON2CSV(options) {
var result = "";
try {
var IO = require('./js/io/io.js');
var io = new IO();
var fileName = process.argv[2];
var content = '';
if (process.argv.length > 2) {
fileName = process.argv[2];
content = io.readFileSync(fileName);
if (JSON.stringify(content).length > 0) {
var data = JSON.parse(content);
for (var v in data) {
result += data[v] + ';\n';
}
var strImportFile = 'import.csv';
if (process.argv.length > 3) {
console.log('Arg:'+process.argv[3]);
strImportFile = process.argv[3];
}
io.writeFileSync(strImportFile, result);
}
}
else {
result = result !== undefined && result.length >0?result:'Bad Request';
}
} catch (error) {
console.error('Exception:' + error + '\n' + error.stack);
} finally {
console.log((result !== undefined && result.length >0)?result:'Bad Request');
}
}
new JSON2CSV();