Thanks to visit codestin.com
Credit goes to www.tutorialspoint.com

What is JSON.parse() and and explain its use in javascript?



JSON.parse()

When the data is received from web server, the data is always a string .So to change it to the object, JSON.parse() method is used. 

Example

 Live Demo

<html>
<body>
<script>
   var obj = '{"name":"Jon", "age":20, "city":"Columbia"}';
   var res = JSON.parse(obj);
   document.write(res);
   console.log(res);
</script>
</body>
</html>

output

[object object]
{"name":"Jon", "age":"20", "city":"Columbia"}
Updated on: 2019-07-30T22:30:26+05:30

176 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements