-
Notifications
You must be signed in to change notification settings - Fork 7
/
aggregateJSONS.js
35 lines (32 loc) · 1.27 KB
/
aggregateJSONS.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
const fs = require('fs');
function aggregate(){
let jsonFilenames = [];
let aggregate = {};
fs.readdirSync('./jsons/').forEach(file => {
if(file.match(/[0-9]{9}.json/)){
let currFileContents = fs.readFileSync('./jsons/' + file);
let currJSON = JSON.parse(currFileContents)
let toAdd = {};
if(currJSON.hasOwnProperty('Variable Label')){
toAdd['Variable Label'] = currJSON['Variable Label']
}
if(currJSON.hasOwnProperty('Variable Name')){
toAdd['Variable Name'] = currJSON['Variable Name']
}
if(!currJSON.hasOwnProperty('Variable Label') && !currJSON.hasOwnProperty('Variable Name') && currJSON.hasOwnProperty('Current Question Text')){
toAdd['Variable Name'] = currJSON['Current Question Text']
}
if(Object.keys(toAdd).length > 0){
aggregate[currJSON['conceptId']] = toAdd;
}
//console.log(file)
}
});
//console.log(JSON.stringify(aggregate));
fs.writeFileSync('aggregate.json', JSON.stringify(aggregate,null, 2))
// fs.writeFileSync('aggregateCopy.json', JSON.stringify(aggregate,null, 2))
}
module.exports = {
aggregate:aggregate
}
aggregate()