Im new to Javascript and I have to print Json output using pretty function, but the output is not as expected, it just prints normal but Im expecting with indentation. I have also gone through the following links, can anyone please help me why this is not working.
How can I pretty-print JSON using JavaScript?
<html>
<script type="text/javascript">
function showJson(){
var jsonString = "{array:[1,2,3],boolean:true,null:null,number:123,object:{a:b,c:d,e:f},string:Hello World}";
document.getElementById('json_output').innerHTML = JSON.stringify(jsonString, null, '\t');
}
function output(inp) {
document.body.appendChild(document.createElement('pre')).innerHTML = inp;
}
</script>
<body>
<input type="button" onclick="showJson();" value="Click Me!!">
<br>
<br>
STRING FROM DEVICE : <div id='json_output'>HI</div>
</body>