In this lesson, we're going to be looking at Jason Passe and Jason Stringer Thig and Storify is not
only fun to say, but it is super useful whenever you want to turn an object into a string and you can
use pass to turn it back into a usable object format.
Got a few examples as well as we'll take a closer look at what Mozilla Developer Network has as an example.
So they've got a typical object here and notice that this is within a string format and when we pass
it into JSON, then we have access to the object.
So run that and we see that we've got count.
So instead of having it within the string, it turns it into a usable object format and then you can
manipulate the values and the other way, going the other way around, of course, is String Afie so
converts a JavaScript object or a value to a JSON string, so string OWFI.
So we're stratifying an object.
So basically it's turning it into a string where stratifying an array and string value boolean values
or turning them all into a usable format within the array as well as stratifying undefined function
with blank function.
So these are all coming back as null.
So that's something to note that as well.
Symbol function and undefined.
When you string Afie them, they come back as null.
So instead of coming back as undefined function because when you string a it, of course it has to be
within a string format and you can't have a function that's sitting within a string format.
So that's where it just comes back as.
Also if you string if I added object.
So a date is also an object.
And when you string a fight, you get this type of output being created so you can run.
And you see you've got the double quotes around there because it already is a coded string around that
object and that's how it was being written.
So we saw that within the last lessem.
So of course, we do have a challenge for you within this lesson, and that is to take an object, convert
it into a string output, into the console as a string, and then take that same object that was turned
into a string and turn it back into an object and output the values.
So for first and last name, really simple object where we've got first and last and turning into a
string and then parsing it back into an object and then outputting the values within the object format.
So go ahead and try this out.
You can pause the video and I'll walk you through the solution for this one.
It's opening up the ED.
First, let's create the object and you can contain whatever information you want within this object.
In this case, I'm going to just use the first and last creating really simple.
So that means that if I go into my object, I can see that it's within an object format.
And if I wanted to get back first, I can get Lowrance back this way and I can also get back lost because
of course it is an object so it can output those values.
So the objective of this exercise was to try this and convert it first into a string to create a string
and using JSON string a fine.
And then we need to pass the object that we want to string and console log out just to make sure that
it is a string.
So no tricks here.
We see that now this object has been turned into a string and you can't really do a whole lot with it.
You've got no option for first or anything like that.
It just comes back undefined because it's a string, it's not an object.
So we want to turn it back into a new object or back into an object.
And this is where we can use JSON pass and taking the my string, we're going to pass it back into an
object format and then using the console.
Let's output the new object and we're going to get first and console log output, the new object, and
we'll get the value for lost.
So when we refresh, we see we got all of those values being output so we can use it again.
And this is really useful, especially when you need to save data or within the browser as a string
and then convert it back into an object to make use of it within your code.
A lot of examples of this to try to.