-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_json.js
33 lines (24 loc) · 952 Bytes
/
parse_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
var Promise = require('bluebird');
var fs = Promise.promisifyAll(require('fs'));
var path = require('path');
// need .catch(error)
function readFiles(dirname, onFileContent, onError) {
fs.readdirAsync(dirname).then(function (filenames) {
filenames.forEach(function (filename) {
fs.readFileAsync(path.resolve(dirname, filename), 'utf-8').then(function (content) {
onFileContent(filename, content);
});
});
});
}
var data = {};
readFiles(path.resolve(__dirname, 'raw_ship_data/'), function (filename, content) {
data[filename] = content;
}, function (error) {
throw err;
});
// I am trying to readFiles().then(create new obj based on the nodes I need from data).then(write new json file with the new obj)
// readFiles works but is not a promise.
// Assuming data now is an object with all our ship data combined.
var keys_array = Object.keys(data)
// Keys I want are ['@name', '@displayname', '@description',