I'm stringyfing an object like {'foo': 'bar'}
How can I turn the string back to an object?
stringify() is the opposite of JSON. parse(), which converts JSON into Javascript objects.
It`s ok to use it with some primitives like Numbers, Strings or Booleans. As you can see, you can just lose unsupported some data when copying your object in such a way. Moreover, JavaScript won`t even warn you about that, because calling JSON. stringify() with such data types does not throw any error.
The JSON. stringify() function will convert any dates into strings.
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) { console.error(ex); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With