Javascript Data Type How to - Convert object into a JSON string array








Question

We would like to know how to convert object into a JSON string array.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
window.onload=function(){<!--  ww  w. ja va 2 s  . c  o  m-->
    var object = {a: "a", b: ['b', 'b2'], c: {c: 'c'}};
    document.writeln(JSON.stringify(object));
    document.writeln('<br/>');
    document.writeln(object);
}
</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: