JSON.parse() function in JavaScript


The JSON.parse() function accepts a JSON string, and constructs an object based on the given text and, returns it.

Syntax

Its Syntax is as follows

Json.parse();

Example

 Live Demo

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var jsonSample = '{"Tutorial": "Java", "Version":8 }';
      jsonObj = JSON.parse(jsonSample);
      document.write("Tutorial Name: " + jsonObj.Tutorial);
      document.write("<br>");
      document.write("Tutorial Version: " + jsonObj.Version);
   </script>
</body>
</html>

Output

Tutorial Name: Java
Tutorial Version: 8

Updated on: 25-Jun-2020

128 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements