-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_parser.js
More file actions
27 lines (25 loc) · 883 Bytes
/
Copy pathjson_parser.js
File metadata and controls
27 lines (25 loc) · 883 Bytes
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
module.exports.extractLabelAndValue=function extractLabelAndValue(data,result,obj={}){
if(typeof data === 'object' && !Array.isArray(data)){
for(item in data){
if('LabelDetection' in data && 'ValueDetection' in data){
if(data.ValueDetection.Text){
const key1 = data.LabelDetection.Text.split('\n');
let key="";
for(let i=0;i<key1.length;i++){
key+=key1[i];
}
obj[key] = data.ValueDetection.Text
}
}else{
extractLabelAndValue(data[item],result,obj);
}
}
}else if(Array.isArray(data)){
let obj={};
for(const arrayItem of data){
extractLabelAndValue(arrayItem,result,obj);
}
if(Object.keys(obj).length !== 0)
result.push(obj);
}
}