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

JSON Parse


JSON Parse

JSON parsing is the process of converting a JSON object in text format to a Javascript object that can be used inside a program. Suppose you make a API project which return JSON Object. when You will recieve that JSON data from a web server, the data is always a string. Parse the data with JSON.parse(), and the data becomes a JavaScript object.

Json stringify

Example

Suppose we have a web API and it is uploaded on web server. So we received this text from a web server:

'{"name":"Rohatash", "age":36, "Email":"test@gmail.com"}'

Use the JavaScript function JSON.parse() to convert text into a JavaScript object:

const parseobj = JSON.parse('{{"name":"Rohatash", "age":36, "Email":"test@gmail.com"}}');

The below example you can use on HTML page

<html>
<body>

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

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

<script>
const jsontxt = '{"name":"Rohatash", "age":36, "Email":"test@gmail.com"}'
const obj = JSON.parse(jsontxt);
document.getElementById("parsetestid").innerHTML = obj.name + ", " + obj.age + ", " + obj.Email;
</script>

</body>
</html>

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

Output

Json stringify


Prev Next