Print json object in JavaScript


/ Published in: JavaScript
Save to your folder(s)

Print json object in JavaScript


Copy this code and paste it in your HTML
  1. var s='';
  2. //--------------------
  3. function get_obj(objel, deep) {
  4.  
  5. var s3= new Array(deep*3).join(' ');
  6.  
  7. for (var el in objel) {
  8.  
  9. s3+=typeof(objel[el])+' : '+el+' = '
  10.  
  11. if (typeof(objel[el])=='object')
  12.  
  13. s3+=String.fromCharCode(13)+String.fromCharCode(10)+
  14. get_obj(objel[el], deep+1);
  15. else {
  16. s3+= objel[el]+String.fromCharCode(13)+String.fromCharCode(10);
  17. }
  18. }
  19. return s3;
  20.  
  21. }
  22. //--------------------
  23. s=get_obj(inf,0);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.