Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reverse of JSON.stringify?

I'm stringyfing an object like {'foo': 'bar'}

How can I turn the string back to an object?

like image 326
thelolcat Avatar asked Jun 23 '12 18:06

thelolcat


People also ask

What is the reverse of JSON Stringify?

stringify() is the opposite of JSON. parse(), which converts JSON into Javascript objects.

Is it bad to use JSON Stringify?

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.

What does JSON Stringify () do?

The JSON. stringify() function will convert any dates into strings.


1 Answers

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); }
like image 194
Chase Florell Avatar answered Oct 05 '22 17:10

Chase Florell