In this short article I will explain how we can parse and convert a JSON string to JSON object using JavaScript eval function
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
    <script type = "text/javascript">
        var json = "{Name: 'Mudassar Khan', Age: 27, City: 'Mumbai', Country: 'India'}";
        function ParseJSON() {
            var person = eval('(' + json + ')');
            document.getElementById("txtName").value = person.Name;
            document.getElementById("txtAge").value = person.Age;
            document.getElementById("txtCity").value = person.City;
            document.getElementById("txtCountry").value = person.Country;
        }
    </script>
</head>
<body>
    <form id="form1">
       <input type = "button" id = "demo" value = "Parse JSON" onclick = "ParseJSON()" />
       <br />
       <div>
        Name: <input type = "text" id = "txtName" /><br />
        Age: <input type = "text" id = "txtAge" /><br />
        City: <input type = "text" id = "txtCity" /><br />
        Country: <input type = "text" id = "txtCountry" /><br />
       </div>
    </form>
</body>
</html>
 
In the above HTML markup we have simple JSON string which is parsed in the button click event handler ParseJSON. Once the JSON is parsed and converted to JSON object the values are assigned to their respective textboxes.
 
Demo
 
Browser Compatibility
The above code has been tested in the following browsers only in versions that support HTML5.
Internet Explorer  FireFox  Chrome  Safari  Opera
* All browser logos displayed above are property of their respective owners.