Show Output
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <title>Convert a JSON String into an Object in JavaScript</title> </head> <body> <script> // Store JSON data in a JS variable var json = '{"name": "Harry", "age": 18, "country": "United Kingdom"}'; // Converting JSON encoded string to JS object var obj = JSON.parse(json); // Accessing individual value from JS object document.write(obj.name + "<br>"); // Outputs: Harry document.write(obj.age + "<br>"); // Outputs: 18 document.write(obj.country); // Outputs: United Kingdom </script> </body> </html>