Use the JSON.parse() method to convert JSON String to JSON Object in JavaScript. JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object.
JSON.parse(string);
Where string
is your json string?
Example Convert JSON String to JSON Object
Simple HTML example code using the JavaScript function JSON.parse() to convert JSON sting into a JavaScript object:
<!DOCTYPE html>
<html>
<head>
<script>
var obj = '{"name":"John", "age":30, "city":"New York"}'
var json = JSON.parse(obj);
console.log(json);
console.log(typeof(json))
</script>
</head>
</html>
Output:
Do comment if you have any doubts or suggestions on this JS JSON string to object conversion code.
Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.
OS: Windows 10
Code: HTML 5 Version