-
Notifications
You must be signed in to change notification settings - Fork 0
/
JsonParser.js
executable file
·45 lines (37 loc) · 1.16 KB
/
JsonParser.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
const replaceString = require('replace-string');
const FileReader = require('./FileReader.js');
/*
JsonReader Class (reads for example classificationsamples.json)
splits between "," (file) and ":" (per line)
Author: Karim Saad
Month/Year: 08/2019
*/
class JsonReader {
constructor(filename) {
this.filename = filename;
this.data=[];
this.readdata();
}
readdata() {
this.data=[];
var kdata = this.data;
var d=FileReader.ReadFile("./classificationsamples.json");
d = d.replace("{","").replace("}","");
d=d.replace('",', '').split("\n");
d.forEach(function (el) {
var t = el.split(":")
if(t.length == 2){
var str = t[0];
var dt = t[1];
dt = dt.split('"')[1].replace('"',"");
str = str.split('"')[1].replace('"',"");
console.log(str, dt);
kdata.push([str, dt]);
}
});
}
getData(){
return this.data;
}
}
module.exports = JsonReader