diff options
author | Chinthakayala, Sheshashailavas (sc2914) <sc2914@us.att.com> | 2017-08-28 05:25:46 -0900 |
---|---|---|
committer | Chinthakayala, Sheshashailavas (sc2914) <sc2914@att.com> | 2017-08-28 05:36:52 -0900 |
commit | d1569975bb18f4359fac18aa98f55b69c248a3ad (patch) | |
tree | c8681eeac12dca8673ccf841705daac88bf01ca6 /dgbuilder/tools/jsonTool.js | |
parent | a016ea661ff5767a3539734c4c07ef974a6e4614 (diff) |
[CCSDK-28] populated the seed code for dgbuilder
updated the code to point to the new package name for sli
Change-Id: I3b5a1d05dc5193664fd4a667afdcd0b2354010a4
Issue-ID:{CCSDK-28}
Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) <sc2914@att.com>
Signed-off-by: Chinthakayala, Sheshashailavas (sc2914) <sc2914@att.com>
Diffstat (limited to 'dgbuilder/tools/jsonTool.js')
-rw-r--r-- | dgbuilder/tools/jsonTool.js | 119 |
1 files changed, 119 insertions, 0 deletions
diff --git a/dgbuilder/tools/jsonTool.js b/dgbuilder/tools/jsonTool.js new file mode 100644 index 00000000..d95ae10d --- /dev/null +++ b/dgbuilder/tools/jsonTool.js @@ -0,0 +1,119 @@ +var obj={}; +function dotToJson(str,value,obj){ + //var objArr = path.split("."), part; + var objArr = str.split("."); + var prevStr; + var currObj; + var prevObj; + //console.log(str); + var isArray = false; + var prevObjIsArray = false; + for(var i=0;i<objArr.length -1;i++){ + var subStr= objArr[i] ; + if(isArray){ + prevObjIsArray = true; + } + isArray = false; + if(subStr.indexOf(']') == subStr.length -1){ + subStr = subStr.substring(0,subStr.length -2); + isArray = true; + } + //console.log("subStr:" + subStr + isArray); + //console.dir(prevObj); + if(isArray){ + if(i==0 && obj[subStr] == undefined ){ + //console.log("i==0 && obj[subStr] "); + obj[subStr]=[]; + }else if(i==0 && obj[subStr][0] == undefined ){ + obj[subStr][0]={}; + }else if(i==0 && obj[subStr][0] != undefined ){ + currObj= obj[subStr][0]; + }else{ + if(i == 1){ + //console.log("i==1 && obj[prevStr] "); + prevObj=obj[prevStr]; + if(prevObj[subStr][0] == undefined){ + prevObj[subStr] = []; + prevObj[subStr][0] = {}; + currObj = prevObj[subStr][0]; + }else{ + currObj = prevObj[subStr][0]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr]=[]; + prevObj[subStr][0]={}; + currObj = prevObj[subStr][0]; + }else{ + currObj = prevObj[subStr][0]; + } + } + } + }else{ + if(i==0 && obj[subStr] == undefined ){ + obj[subStr] = {}; + currObj= obj[subStr]; + }else if(i==0 && obj[subStr] != undefined ){ + currObj=obj[subStr]; + //console.log("in gkjgjkg"); + }else{ + if(i == 1){ + prevObj=obj[prevStr]; + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + }else{ + if(prevObj[subStr] == undefined){ + prevObj[subStr] = {}; + currObj = prevObj[subStr]; + }else{ + currObj = prevObj[subStr]; + } + } + } + } + prevStr=subStr; + if(i <objArr.length-2){ + //console.dir(currObj); + prevObj=currObj; + } + } + var lastStr = objArr[objArr.length-1]; + if(isArray){ + currObj[lastStr] = value; + }else{ + currObj[lastStr] = value; + } + //prevObj[lastStr] = value; + //console.dir(currObj); + return obj; +} +function printObj(obj){ +for( j in obj){ + console.log(j + ":" + obj[j]); + if(typeof obj[j] == "object" ){ + printObj(obj[j]); + } + +} +} + +var a=[]; +var nObj={}; +for(var i=0;i<a.length;i++){ + dotToJson(a[i],'',nObj); +} + +var nObj={}; +for(var i=0;i<a.length;i++){ + var key =a[i].substring(0,a[i].indexOf(':')); + console.log(key); + var value =a[i].substring(a[i].indexOf(':') +1); + if(value == undefined) value =""; + dotToJson(key,value,nObj); +} +console.log(JSON.stringify(nObj,null,4)); +//console.log (stringToObj('abc.ebg.h',"",{})); |