Welcome back.
Let's next we're going to talk about Jason.
So Jason stands for JavaScript Object Notation as this relates a lot to objects, but also relates to
ways to save data and send data across the Internet.
So what it does is it does what's called serializing and these serializing objects, which just means
converting it to a string and then back into objects.
There's a couple of things that we can do to do this.
One is Jason Pass Jason that pass, which takes a string and makes an object out of it.
And then there's Jason, that string of PHI, which takes an object and makes a string out of it.
So that's what we're going to look at next.
So we're going to start with our bill example and let's get rid of all the things that we're doing with
Bill.
Except for slugging it out at the end, so we have our object named EMP and has the information about
it.
So what we can do is we can use the JSON, that string of to string of five, this employee.
So we'll say let em string equals Jason dot string of high up.
And then instead of outputting the EMP, well I'll put the upstream.
And then it puts it into this JSON notation and so you can see here that it says a curly brace and a
curly brace is the beginning in the end of an object.
And this looks exactly like how we're defining this object.
Curly brace, curly brace.
But it's the string is the difference.
So everything here is exactly how it looks.
To the left, we have our name, Bill.
No.
One, two, three, four, five.
Full time true salary.
Ten shifts is an array, but the difference is that we can take this and we can copy it and do something
with it.
Sorry, is notepad program note pad plus.
Plus I just pasted in here and there we have it inside of a text editor that we can use later.
So let's go back to our program for a second.
Now that we've converted to a string, let's convert it back into an object.
So we would say let obj equals Jason that pass.
I'm straight and we want to get out.
All right, so then we have our string and now we have our object back in this object notation.
Now, what can we do with this now that we have a string, so let's say instead of creating one object,
we created a array that has a simply so do that.
All we need to do is put square brackets around it.
So it's bracket here, you end up with a square bracket and now we have an array of employees, except
that we only have one employee.
So let's run that and see what the difference is.
So it puts the square bracket here and here, it's in an array notation to break it down, this length
of one in the array in that.
So let's copy this instead of the other thing and go back to that notepad or paste it in here.
So let's get rid of defining it here and what we're going to do, we'll say, equals let's start all
the way down here.
But scoring equals prompt answer the employees.
So what I'm doing is taking a simplistic way of saying, asking for a website to give me the employees
I want to display on my screen.
So I'm just going to type them in instead of the website giving them to me.
So I'm going to get my hamstring.
I'm going to convert it to an object.
So let's run this.
Or run, if we get our prompt, I'm just going to go back to this dopehead plus plus and copy this
and pasted it in here.
So there it is, turn into an object again.
Now, let's say that we want to do is read in our current database, which is you can think of this
as a database, a set of data that's stored.
And we want to add another employee to it so we can say we've read our employee object and we know it's
an array.
So we say let new AMP equals and we'll create a new employee.
And then we were created with the same format as the old employee.
So let's let's get that out of here and just use this to change some of the information.
So we don't want an array, we just want an object.
So it's just kind of formatted ourselves.
Now you can have the the quotes in around me, the names, but it's not really standard to do when you're
defining an object in JavaScript.
So I'm going to get rid of them.
I do a line, I quite like that.
OK, so we're defining another bill, so we want to change the misinformation or Defensa and her employer
numbers one, two, three, four, six, and full time.
Still true or salary, let's say, is 11.
And she works Sundays, Mondays, Tuesdays and Wednesdays and then off the rest of the week.
All right.
So we have a new employee, a new employee, and we've got an employee object, so we want to add it
to it.
So what we do is say up about that, push the new EP and then it's going we can output the object,
but if we want to save the data, we want to save it as the string.
So we'll say get back upstream and say equals Jace on that string of five amp and then we'll output
that.
All right.
So we need to go back here and get our current data set and database pasted in here so that it has the
starting data, and then you can see here that output an array of two.
So we have Bill and we have Sue and we got the string output again.
So we can go in here and just copy this and put it into our notepad.
Now we've got more.
So if we run this again, we're going to add another Sue, obviously, because unless you want to change
all that information again so we can run it again
at this, which is a longer set of data, and now we have three two sues and one bill.
So you see that that the way that we use the Jason is we can store any amount of data we want in it,
and it's used for like sending information and receiving information is its primary purpose.