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 ""; } }