xFactorSchool.com(Beta)
How to Do Examples
Python Examples
HTML Examples
Code Examples
C Code Examples
C++ Code Examples
C# Code Examples
Java Code Examples
Python Code Examples
HTML Code Examples
CSS Code Examples
JavaScript Code Examples
Online Editor
C Code Editor
C++ Code Editor
C# Code Editor
Java Code Editor
Python Code Editor
HTML Code Editor
CSS Code Editor
JavaScript Code Editor
Practice how to convert a JSON string into a JavaScript object in JavaScript
JavaScript Online Editor
Run Code
More JavaScript Sample Codes
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>How to convert a JSON string into a JavaScript object in JavaScript</title> <!--Script is added to write JavaScript code inside it--> <script> //create a JSON string const jsonString = '{"name":"John Smith", "age": 19}'; // JSON string is created in key-value pair //Convert the string into a JS object var jsObject = JSON.parse(jsonString); // JSON.parse() method is used to convert JSON string into a JavaScript object //get JS object property values var olbjectData = jsObject.name + " is "+ jsObject.age + " years old." function myFunction() { //displaying JS object property values document.getElementById("outPut").innerHTML = "<p>Output from a JavaScript Object :</P>" + olbjectData; }; </script> </head> <body> <h1>How to convert a JSON string into a JavaScript object in JavaScript</h1> <button onclick="myFunction()">Click here to see result</button> <p id="outPut"></p> </body> </html>