-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_json.js
58 lines (44 loc) · 1.31 KB
/
create_json.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
var fs = require('fs');
var readline = require('readline');
var old_data = require('./data/input/projects_old_data.js');
//console.log(old_data);
old_data.forEach(function(el,i){
el.id = i;
});
var old_data_json = JSON.stringify(old_data);
var output_path = 'data/output/old_project_data.json';
fs.writeFile(output_path,old_data_json,function(err){
if(err){ return console.log(err) };
console.log('we wrote the file!');
});
/*var r1 = readline.createInterface(process.stdin,process.stdout);
var jsonFile = JSON.stringify(objArray);
if(!fs.existsSync('myData1.json')){
fs.writeFile('myData1.json', jsonFile, function (err) {
if (err) return console.log(err);
console.log("we created a new file!");
});
}else{
r1.question("The file already exists. Do you want to overwrite it? (Y/N)", function(answer){
if(answer.toLowerCase().trim() == 'y'){
fs.writeFile('myData1.json', jsonFile, function (err) {
if (err) return console.log(err);
console.log("we overwrote the data file");
r1.close();
});
}else{
console.log("user is undecided");
r1.close();
};
});
};
r1.on('close',function(){
console.log("closing the interface");
process.exit();
});
*/
/*fs.readFile('myData.json', function(err,data){
if (err) throw err;
var jsObj = JSON.parse(data);
console.log(jsObj[0].name);
});*/