Display and prettify returned JSON objects - Javascript JSon

Javascript examples for JSon:JSon Object

Description

Display and prettify returned JSON objects

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <style id="compiled-css" type="text/css">
body { white-space: pre; font-family: monospace; }
      </style> 
      <script type="text/javascript">
    window.onload=function(){/* w  w w. j av a  2 s .c om*/
var obj = {"hello":"world", "Test":["hello"]}
document.body.innerHTML = "";
document.body.appendChild(document.createTextNode(JSON.stringify(obj, null, 4)));
    }

      </script> 
   </head> 
   <body>  
   </body>
</html>

Related Tutorials