From 324ee36fe31763e507b422ab0a88e4230045e205 Mon Sep 17 00:00:00 2001 From: "Timoney, Daniel (dt5972)" Date: Wed, 15 Feb 2017 10:37:53 -0500 Subject: Initial commit for OpenECOMP SDN-C OA&M Change-Id: I7ab579fd0d206bf356f36d52dcdf4f71f1fa2680 Signed-off-by: Timoney, Daniel (dt5972) Former-commit-id: 2a9f0edd09581f907e62ec4689b5ac94dd5382ba --- dgbuilder/tools/json_to_html | 139 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 139 insertions(+) create mode 100644 dgbuilder/tools/json_to_html (limited to 'dgbuilder/tools/json_to_html') diff --git a/dgbuilder/tools/json_to_html b/dgbuilder/tools/json_to_html new file mode 100644 index 00000000..51afe452 --- /dev/null +++ b/dgbuilder/tools/json_to_html @@ -0,0 +1,139 @@ +try{ +var jsonStr='{}'; +jsonObj=JSON.parse(jsonStr); +var objectId =0; +var level=0; +var htmlStr="" +htmlStr += ""; +htmlStr += ""; +htmlStr += ""; +htmlStr += ""; +htmlStr += ""; +htmlStr += "
\n\n"; +printObjectValues(jsonObj,level); +htmlStr += "\n
\n
"; +//var pattern = new RegExp("\\n","g"); +//htmlstr =htmlStr.replace(pattern,''); +htmlStr += ""; +console.log(htmlStr); + +function tabs(level){ +return ''; +} +function tabsOrig(level){ + var tabs=""; + for(var i=0;i\n" ; + objectHtmlStr += tabs(level+1 ) +"\n" ; + + var str=printObjectValues(v,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2) + objectHtmlStr + "
" + key + "\n"; + htmlStr +="\n"; + } + + htmlStr += tabs(level+1) + "
\n" ; + htmlStr += tabs(level) + "\n"; + }else if(typeof v === 'object' && Array.isArray(v) === true){ + var idVal = objectId++; + level++; + objectHtmlStr += tabs(level) + "
\n"; + objectHtmlStr += tabs(level+1) + "\n"; + + var str = printArrayValues(v,key,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2) + objectHtmlStr + "
" + key + "\n"; + htmlStr+="\n"; + } + + htmlStr += tabs(level+1) + "
\n" ; + htmlStr += tabs(level) + "
\n"; + }else{ + output += tabs(level) +"" + key + "" + printValue(v) + "\n"; + } + } +} +}catch(err){ + console.log(err); +} +return output; +} + +}catch(err){ +console.log( err ); +} + +function printArrayValues(arrObj,key,level){ +var output =""; +var arrayHtmlStr =""; +try{ + for(var i=0;arrObj != null && i\n" ; + arrayHtmlStr += tabs(level+1 ) +"\n" ; + + var str = printObjectValues(o,level+2); + if(str != null && str != ''){ + htmlStr += tabs(level+2 ) + arrayHtmlStr + "
" +key + "[" + i + "]" + "\n"; + htmlStr+="\n"; + } + htmlStr += tabs(level+1) + "
\n"; + htmlStr += tabs(level) + "\n"; + }else if(typeof o === 'object' && Array.isArray(v) === true){ + var idVal = objectId++; + level++; + arrayHtmlStr += tabs(level) + "
\n" ; + arrayHtmlStr += tabs(level+1 ) +"\n" ; + + var str = printArrayValues(o,key,level); + if(str != null && str != ''){ + htmlStr += tabs(level+2 ) + arrayHtmlStr + "
Array\n"; + htmlStr+="\n"; + } + + htmlStr += tabs(level+1) + "
\n"; + htmlStr += tabs(level) + "
\n"; + }else{ + output += tabs(level) + "" + printValue(o) + "\n"; + } + } +}catch(err){ + console.log(err); +} +return output; +} + +function printValue(obj){ + if(obj != undefined){ + return obj; + }else{ + return ""; + } +} -- cgit 1.2.3-korg