Javascript Convert String Json to Object – eval()

Sometimes we need to convert string json to object especially ajax response.

You can do this with eval()

[js]
var str = "{\"name\" : \"john\", \"age\" : 21}";
var obj = eval(‘(‘ + str + ‘)’);

[/js]