1 00:00:01,360 --> 00:00:02,160 Welcome back. 2 00:00:02,220 --> 00:00:04,820 Let's next we're going to talk about Jason. 3 00:00:07,780 --> 00:00:15,520 So Jason stands for JavaScript Object Notation as this relates a lot to objects, but also relates to 4 00:00:15,520 --> 00:00:19,970 ways to save data and send data across the Internet. 5 00:00:20,980 --> 00:00:27,550 So what it does is it does what's called serializing and these serializing objects, which just means 6 00:00:27,550 --> 00:00:30,340 converting it to a string and then back into objects. 7 00:00:30,730 --> 00:00:32,470 There's a couple of things that we can do to do this. 8 00:00:32,470 --> 00:00:38,130 One is Jason Pass Jason that pass, which takes a string and makes an object out of it. 9 00:00:39,730 --> 00:00:44,470 And then there's Jason, that string of PHI, which takes an object and makes a string out of it. 10 00:00:46,200 --> 00:00:47,770 So that's what we're going to look at next. 11 00:00:50,650 --> 00:00:55,570 So we're going to start with our bill example and let's get rid of all the things that we're doing with 12 00:00:55,570 --> 00:00:55,990 Bill. 13 00:00:59,810 --> 00:01:07,460 Except for slugging it out at the end, so we have our object named EMP and has the information about 14 00:01:07,880 --> 00:01:07,940 it. 15 00:01:08,600 --> 00:01:14,300 So what we can do is we can use the JSON, that string of to string of five, this employee. 16 00:01:15,350 --> 00:01:24,170 So we'll say let em string equals Jason dot string of high up. 17 00:01:26,240 --> 00:01:30,020 And then instead of outputting the EMP, well I'll put the upstream. 18 00:01:34,850 --> 00:01:43,400 And then it puts it into this JSON notation and so you can see here that it says a curly brace and a 19 00:01:43,400 --> 00:01:46,000 curly brace is the beginning in the end of an object. 20 00:01:46,520 --> 00:01:49,880 And this looks exactly like how we're defining this object. 21 00:01:50,540 --> 00:01:51,710 Curly brace, curly brace. 22 00:01:51,710 --> 00:01:53,670 But it's the string is the difference. 23 00:01:54,650 --> 00:01:59,510 So everything here is exactly how it looks. 24 00:01:59,510 --> 00:02:02,210 To the left, we have our name, Bill. 25 00:02:02,540 --> 00:02:02,750 No. 26 00:02:02,810 --> 00:02:04,010 One, two, three, four, five. 27 00:02:04,190 --> 00:02:06,710 Full time true salary. 28 00:02:06,710 --> 00:02:15,050 Ten shifts is an array, but the difference is that we can take this and we can copy it and do something 29 00:02:15,050 --> 00:02:15,330 with it. 30 00:02:16,820 --> 00:02:19,160 Sorry, is notepad program note pad plus. 31 00:02:19,160 --> 00:02:27,120 Plus I just pasted in here and there we have it inside of a text editor that we can use later. 32 00:02:28,160 --> 00:02:30,220 So let's go back to our program for a second. 33 00:02:31,160 --> 00:02:35,410 Now that we've converted to a string, let's convert it back into an object. 34 00:02:36,030 --> 00:02:42,410 So we would say let obj equals Jason that pass. 35 00:02:44,990 --> 00:02:50,290 I'm straight and we want to get out. 36 00:02:58,110 --> 00:03:05,730 All right, so then we have our string and now we have our object back in this object notation. 37 00:03:08,600 --> 00:03:15,200 Now, what can we do with this now that we have a string, so let's say instead of creating one object, 38 00:03:15,200 --> 00:03:19,630 we created a array that has a simply so do that. 39 00:03:19,640 --> 00:03:22,120 All we need to do is put square brackets around it. 40 00:03:24,380 --> 00:03:30,200 So it's bracket here, you end up with a square bracket and now we have an array of employees, except 41 00:03:30,200 --> 00:03:31,450 that we only have one employee. 42 00:03:32,270 --> 00:03:34,100 So let's run that and see what the difference is. 43 00:03:37,370 --> 00:03:43,190 So it puts the square bracket here and here, it's in an array notation to break it down, this length 44 00:03:43,190 --> 00:03:45,680 of one in the array in that. 45 00:03:48,740 --> 00:03:57,590 So let's copy this instead of the other thing and go back to that notepad or paste it in here. 46 00:04:00,680 --> 00:04:12,890 So let's get rid of defining it here and what we're going to do, we'll say, equals let's start all 47 00:04:12,890 --> 00:04:14,090 the way down here. 48 00:04:21,170 --> 00:04:29,570 But scoring equals prompt answer the employees. 49 00:04:32,120 --> 00:04:38,630 So what I'm doing is taking a simplistic way of saying, asking for a website to give me the employees 50 00:04:38,630 --> 00:04:39,970 I want to display on my screen. 51 00:04:40,280 --> 00:04:44,390 So I'm just going to type them in instead of the website giving them to me. 52 00:04:44,990 --> 00:04:46,490 So I'm going to get my hamstring. 53 00:04:46,520 --> 00:04:48,620 I'm going to convert it to an object. 54 00:04:49,430 --> 00:04:50,840 So let's run this. 55 00:04:55,550 --> 00:05:02,760 Or run, if we get our prompt, I'm just going to go back to this dopehead plus plus and copy this 56 00:05:05,700 --> 00:05:06,780 and pasted it in here. 57 00:05:10,670 --> 00:05:14,280 So there it is, turn into an object again. 58 00:05:15,320 --> 00:05:23,390 Now, let's say that we want to do is read in our current database, which is you can think of this 59 00:05:23,390 --> 00:05:26,660 as a database, a set of data that's stored. 60 00:05:27,620 --> 00:05:37,580 And we want to add another employee to it so we can say we've read our employee object and we know it's 61 00:05:37,580 --> 00:05:38,290 an array. 62 00:05:38,750 --> 00:05:47,210 So we say let new AMP equals and we'll create a new employee. 63 00:05:49,820 --> 00:05:53,510 And then we were created with the same format as the old employee. 64 00:05:53,520 --> 00:06:01,340 So let's let's get that out of here and just use this to change some of the information. 65 00:06:07,780 --> 00:06:10,180 So we don't want an array, we just want an object. 66 00:06:13,390 --> 00:06:16,050 So it's just kind of formatted ourselves. 67 00:06:16,910 --> 00:06:22,900 Now you can have the the quotes in around me, the names, but it's not really standard to do when you're 68 00:06:23,650 --> 00:06:26,110 defining an object in JavaScript. 69 00:06:27,000 --> 00:06:28,110 So I'm going to get rid of them. 70 00:06:35,050 --> 00:06:38,890 I do a line, I quite like that. 71 00:06:40,330 --> 00:06:47,320 OK, so we're defining another bill, so we want to change the misinformation or Defensa and her employer 72 00:06:47,320 --> 00:06:51,090 numbers one, two, three, four, six, and full time. 73 00:06:51,100 --> 00:06:54,010 Still true or salary, let's say, is 11. 74 00:06:54,790 --> 00:07:06,790 And she works Sundays, Mondays, Tuesdays and Wednesdays and then off the rest of the week. 75 00:07:07,450 --> 00:07:07,750 All right. 76 00:07:07,750 --> 00:07:12,670 So we have a new employee, a new employee, and we've got an employee object, so we want to add it 77 00:07:12,670 --> 00:07:12,960 to it. 78 00:07:12,960 --> 00:07:24,010 So what we do is say up about that, push the new EP and then it's going we can output the object, 79 00:07:24,010 --> 00:07:27,220 but if we want to save the data, we want to save it as the string. 80 00:07:27,850 --> 00:07:42,400 So we'll say get back upstream and say equals Jace on that string of five amp and then we'll output 81 00:07:42,400 --> 00:07:42,700 that. 82 00:07:49,780 --> 00:07:50,170 All right. 83 00:07:54,890 --> 00:08:04,490 So we need to go back here and get our current data set and database pasted in here so that it has the 84 00:08:04,490 --> 00:08:10,030 starting data, and then you can see here that output an array of two. 85 00:08:10,880 --> 00:08:16,970 So we have Bill and we have Sue and we got the string output again. 86 00:08:16,970 --> 00:08:22,430 So we can go in here and just copy this and put it into our notepad. 87 00:08:25,220 --> 00:08:26,270 Now we've got more. 88 00:08:27,170 --> 00:08:32,780 So if we run this again, we're going to add another Sue, obviously, because unless you want to change 89 00:08:32,780 --> 00:08:36,050 all that information again so we can run it again 90 00:08:38,930 --> 00:08:44,540 at this, which is a longer set of data, and now we have three two sues and one bill. 91 00:08:46,970 --> 00:08:54,740 So you see that that the way that we use the Jason is we can store any amount of data we want in it, 92 00:08:55,340 --> 00:09:01,280 and it's used for like sending information and receiving information is its primary purpose.