-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjsonparser.js
More file actions
41 lines (36 loc) · 1.19 KB
/
jsonparser.js
File metadata and controls
41 lines (36 loc) · 1.19 KB
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
var jsonexport = require('jsonexport');
var fs = require('fs');
const csvjson = require('csvjson');
fs.readFile('.//files/data.json', 'utf8', function(err, contents) {
const data = JSON.parse(contents)
var results=[]
var dot=Object.keys(data);
var lan=Object.values(data);
results.push(lan);
// results.shift();
console.log('its lan',results);
// console.log(results);
jsonexport(results,function(err, csv){
if(err) return console.log(err);
fs.writeFile(".//files/file.csv", csv ,function(err, result) {
if(err)
console.log('error', err);
})
})
})
/* readFile('.//files/data.json', 'utf-8', (err, fileContent) => {
if (err) {
console.log(err); // Do something to handle the error or just throw it
throw new Error(err);
}
const csvData = csvjson.toCSV(fileContent, {
headers: 'key'
});
writeFile('.//files/generated.csv', csvData, (err) => {
if(err) {
console.log(err); // Do something to handle the error or just throw it
throw new Error(err);
}
console.log('Success!');
});
}) */