This Angular tutorial helps you get started with Angular quickly and effectively through many practical examples.

JSON Stringify


JSON Stringify

JSON stringify is the process of converting a javaScript object in JSON object that can be used inside a program. when You sending data to a web server, the data should be in string format. So you need to convert a JavaScript object into a string with JSON.stringify().

Json stringify

Example

Suppose we have a object in JavaScript as following:

const javascriptobject={name:"Rohatash", age:36, email:"test@gmail.com"};

Use the JavaScript function JSON.stringify() to convert JavaScript object into a string.

const myJSON = JSON.stringify(javascriptobject);

The below example you can use on HTML page

<html>
<body>

<h2>JSON String from a JavaScript Object </h2>

<p id="parsetestid"></p>

<script>
const javascriptobject= {name:"Rohatash", age:36, email:"test@gmail.com"};
const myJSON = JSON.stringify(javascriptobject);
document.getElementById("parsetestid").innerHTML = myJSON
</script>

</body>
</html>

Now run the code on browser. The following output will show:

Output

Json stringify


Prev Next