-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconvertJSONtoArray.js
33 lines (27 loc) · 958 Bytes
/
convertJSONtoArray.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
var jsonInput = require("./output.json");
// for (var i = 0; i < ; i++) {
// var obj = jsonInput[i];
// for (var key in obj) {
// console.log(key);
// }
// console.log(i);
// }
function isNumeric(num){
return !isNaN(num)
}
var stringOutput = "var addressPoints = [";
for (var i = 0; i < jsonInput.products_found.length; i++) {
if (isNumeric(jsonInput.products_found[i].latitude) && isNumeric(jsonInput.products_found[i].longitude) &&
jsonInput.products_found[i].latitude != "0.0" && jsonInput.products_found[i].longitude != "0.0") {
stringOutput += "[" + jsonInput.products_found[i].latitude + ", " +
jsonInput.products_found[i].longitude + "],\n";
}
}
if (stringOutput.charAt(stringOutput.length - 2) == ",") {
stringOutput = stringOutput.substr(0, stringOutput.length - 2);
}
// if (stringOutput == ",") {
// console.log("fds");
// }
stringOutput += "];";
console.log(stringOutput);