-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (71 loc) · 1.83 KB
/
index.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
var jsonObj = require("./rows");
const fs = require('fs');
const path = require('path');
/** Taking Array Values from rows.json file */
let arrayValues = [];
for (let i = 1; i < jsonObj.data.length; i++) {
arrayValues[i] = jsonObj.data[i];
}
/** Taking common key values for each array data */
const keyValues = [
'key',
'id',
'averageRating',
'createdAt',
'attribution',
'updatedAt',
'attributionLink',
'format',
'name',
'address',
'item',
'count',
'message',
'authCode',
'icComplete',
'displayType',
'hideFromCatalog',
'hideFromCatalog',
'hideFromCatalog',
'hideFromCatalog',
'length',
'hideFromCatalog',
'hideFromCatalog',
'hideFromCatalog',
'width',
'oid'
]
const addressKeyValues = [
'description',
'long',
'lat',
'newBackend',
'publicationAppendEnabled'
]
/** Merging Two arrays and converting it into object */
const convertArrayToObject = (key, arrayData) => Object.assign(...key.map((value, index) => ({
[value]: arrayData[index]
})));
/** Create Object Set from each merging Arrays */
const createObjectSet = (indexValue) => {
let dataSet = {};
dataSet = convertArrayToObject(keyValues, arrayValues[indexValue]);
delete dataSet.address;
address = convertArrayToObject(addressKeyValues, arrayValues[indexValue][9]);
dataSet.address = address;
return dataSet;
}
let allDataSet = [];
for (let x = 1; x < arrayValues.length; x++) {
let allData = {};
allData = createObjectSet(x);
allDataSet.push(allData);
}
console.log(allDataSet);
/** createing new file and writing file with the all Data Set value */
try {
fs.writeFileSync(path.resolve(__dirname, 'data.json'), JSON.stringify(allDataSet));
console.log("file write successfully done");
} catch (err) {
console.log(err);
}