Q:

How to Parse JSON in JavaScript

0

How to Parse JSON in JavaScript

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Use the JSON.parse() Method

You can simply use the JSON.parse() method to parse a JSON string in JavaScript.

The following example will show you how to convert a JSON string into a JS object and access individual values with pure JavaScript. It works in all major browsers.

<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
alert(obj.name); // Outputs: Harry
alert(obj.age); // Outputs: 18
alert(obj.country); // Outputs: United Kingdom
</script>

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

JavaScript / jQuery Frequently Asked Questions

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to Split a String into an Array of Characters ... >>
<< How to Detect Screen Resolution with JavaScript...