thelolcat thelolcat - 2 years ago 370
Javascript Question

Reverse of JSON.stringify?

I'm stringyfing an object like

{'foo': 'bar'}

How can I turn the string back to an object?

Answer Source

You need to JSON.parse() the string.

var str = '{"hello":"world"}';
try {
  var obj = JSON.parse(str); // this is how you parse a string into JSON 
  document.body.innerHTML += obj.hello;
} catch (ex) {

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download