1 00:00:05,100 --> 00:00:10,410 In this video, we're going to discuss JSON or JavaScript object notation. 2 00:00:10,440 --> 00:00:12,510 Why is this important? 3 00:00:13,230 --> 00:00:19,590 It's important because in the CNA blueprint there's a section under automation and programmability. 4 00:00:19,890 --> 00:00:23,700 6.7 Interpret JSON encoded data. 5 00:00:24,750 --> 00:00:26,940 This is something that you need to know for the exam. 6 00:00:26,940 --> 00:00:31,290 So make sure that you watch this video and that you understand, Jason. 7 00:00:33,270 --> 00:00:33,540 Okay. 8 00:00:33,540 --> 00:00:38,010 So let's start with why you've probably seen one of these before. 9 00:00:38,850 --> 00:00:41,220 Are you a human or a robot? 10 00:00:41,860 --> 00:00:48,280 Now the reason we have CAPTCHAs is because machines struggle with unformed data. 11 00:00:48,790 --> 00:00:53,440 If the data isn't clear, machines will struggle to interpret the data. 12 00:00:53,650 --> 00:00:56,300 JSON is a way to format data. 13 00:00:56,320 --> 00:01:00,070 It's also a way to send data from one machine to another. 14 00:01:00,100 --> 00:01:05,290 We as humans can interpret data quite easily, especially if it's slightly off. 15 00:01:05,319 --> 00:01:12,280 So as an example, if you type show version on a Cisco iOS device, so let's say classic iOS, the output 16 00:01:12,280 --> 00:01:19,690 will be different to a Cisco iOS X device, which is different to a Cisco Nexus device. 17 00:01:19,900 --> 00:01:21,890 The output will vary slightly. 18 00:01:21,910 --> 00:01:23,980 Now, that's not a problem for us as humans. 19 00:01:23,980 --> 00:01:30,100 We can make adjustments for the slight changes in the output of the data, but machines struggle with 20 00:01:30,100 --> 00:01:30,610 that. 21 00:01:30,610 --> 00:01:37,330 So we want data that is consistently formatted properly so that machines can communicate properly. 22 00:01:37,360 --> 00:01:45,610 As an example, if I switch to a switch using Python, so I connect to the switch using Python and type 23 00:01:45,610 --> 00:01:47,950 show IP route or show version. 24 00:01:48,310 --> 00:01:56,110 If I'm not using a JSON format, so the output is not formatted in JSON format or another format such 25 00:01:56,110 --> 00:02:02,410 as XML or YAML, it's difficult to write code that can interpret the data properly. 26 00:02:02,560 --> 00:02:08,500 Now, if Cisco once again have made things easier using pirates, so if you use pirates rather than 27 00:02:08,500 --> 00:02:15,250 say net mico to connect directly to a device using a Python script, the output comes back in a format 28 00:02:15,250 --> 00:02:17,650 that's easy to interpret using a Python script. 29 00:02:17,650 --> 00:02:23,770 But if you're using pure net mico or pure telnet and you simply typing show version and you're trying 30 00:02:23,770 --> 00:02:30,370 to pass that output, it's very difficult to write good python code to pass the output, number one, 31 00:02:30,370 --> 00:02:34,690 and secondly, to handle a situation when the output changes. 32 00:02:34,690 --> 00:02:38,800 So you upgrade the router as an example and the output formatting is different. 33 00:02:38,830 --> 00:02:41,830 Your python code will struggle to interpret that. 34 00:02:41,830 --> 00:02:48,310 So for machine to machine communication, it makes sense to use standard output and it makes sense to 35 00:02:48,310 --> 00:02:51,860 have a format that's easy to interpret, especially for machines. 36 00:02:51,880 --> 00:02:54,140 So to help us with JSON formatting. 37 00:02:54,160 --> 00:02:55,690 Let's start with a Tesla. 38 00:02:56,940 --> 00:02:57,150 Okay. 39 00:02:57,150 --> 00:02:59,400 I'm going to ask you some questions about this Tesla. 40 00:02:59,940 --> 00:03:02,400 Well, first question is, who's the manufacturer? 41 00:03:03,070 --> 00:03:04,240 That would be Tesla. 42 00:03:04,390 --> 00:03:06,370 What type of model is this? 43 00:03:07,060 --> 00:03:08,050 Model X. 44 00:03:09,420 --> 00:03:15,750 Notice how I've formatted this data manufacturer, Colon Tesla. 45 00:03:16,080 --> 00:03:19,470 This is known as a key and this is known as a value. 46 00:03:19,620 --> 00:03:21,900 So we've got a key value pair. 47 00:03:22,260 --> 00:03:23,610 What is the model? 48 00:03:23,640 --> 00:03:30,570 It's model X color, white fuel, electric miles per gallon. 49 00:03:30,570 --> 00:03:33,060 City 99 miles per gallon. 50 00:03:33,060 --> 00:03:34,500 Highway 93. 51 00:03:35,500 --> 00:03:37,900 Now I've simply pulled this information off Google. 52 00:03:37,930 --> 00:03:41,740 Hopefully it's correct, but don't get hung up about the data. 53 00:03:42,100 --> 00:03:44,950 Look at the format of the data. 54 00:03:44,980 --> 00:03:52,060 Again, we have what's called a key separated by colon, and then we have a value. 55 00:03:52,090 --> 00:03:54,610 You need to understand JSON formatting. 56 00:03:54,610 --> 00:03:58,000 That's an example of JSON formatting. 57 00:03:59,190 --> 00:04:00,740 It actually looks like this. 58 00:04:00,750 --> 00:04:03,150 We have to use double inverted commas. 59 00:04:03,390 --> 00:04:09,240 So it would be something like first name Colon, then David as an example. 60 00:04:09,360 --> 00:04:13,710 So JSON data is written as name of value pairs. 61 00:04:14,130 --> 00:04:16,920 So going back here, I said key. 62 00:04:16,950 --> 00:04:19,350 It could be also referred to as a name. 63 00:04:19,350 --> 00:04:20,700 So name value pair. 64 00:04:21,510 --> 00:04:25,670 Another example is last name and a value name. 65 00:04:25,690 --> 00:04:33,090 Value pair consists of a field in double quotes followed by a colon followed by a value. 66 00:04:33,120 --> 00:04:35,910 Make sure you understand that format. 67 00:04:36,450 --> 00:04:41,740 Now for the exam they are two JSON data types that you need to know objects and arrays. 68 00:04:41,760 --> 00:04:43,470 Let's start with an object. 69 00:04:44,040 --> 00:04:47,460 So adjacent object would look something like this. 70 00:04:47,820 --> 00:04:51,480 Notice we've got curly braces. 71 00:04:51,720 --> 00:04:58,530 Data is surrounded by curly braces and it's an unordered collection of key value pairs. 72 00:04:58,860 --> 00:05:01,680 So here's our key first name, David. 73 00:05:01,680 --> 00:05:06,160 A lost name, bumble notice, separated by a comma. 74 00:05:06,180 --> 00:05:12,870 Make sure that you know the format so curly braces surrounds the data. 75 00:05:13,230 --> 00:05:15,280 We've got key value. 76 00:05:15,300 --> 00:05:18,840 The keys and values use double quotes, not single quotes. 77 00:05:19,560 --> 00:05:24,450 Each key value pair is separated by a comma, except the last one. 78 00:05:24,780 --> 00:05:27,840 Trailing commas must not be used. 79 00:05:28,500 --> 00:05:34,470 Now it's going to be easier to look at it in this format, easier to read spaces or not important with 80 00:05:34,470 --> 00:05:35,190 JSON. 81 00:05:35,340 --> 00:05:38,460 So notice the curly braces. 82 00:05:39,270 --> 00:05:41,490 First key first value. 83 00:05:42,550 --> 00:05:48,280 Second key, second value separated by comma, comma. 84 00:05:48,280 --> 00:05:50,320 Third key. 85 00:05:50,950 --> 00:05:52,000 Third value. 86 00:05:52,030 --> 00:05:53,080 No comma. 87 00:05:53,500 --> 00:05:56,080 So if you put a comma here, that would be a problem. 88 00:05:56,620 --> 00:06:00,520 Make sure once again that you recognize this format for the exam. 89 00:06:01,680 --> 00:06:08,260 So just to summarize, a JSON object is an unordered collection of key value pairs. 90 00:06:08,280 --> 00:06:10,230 In other words, this is not ordered. 91 00:06:10,230 --> 00:06:11,370 It could be in any order. 92 00:06:11,390 --> 00:06:12,300 Doesn't matter. 93 00:06:12,540 --> 00:06:19,740 Surrounded by curly braces once again, key and value pairs are separated by a colon. 94 00:06:19,740 --> 00:06:25,530 Spacers don't matter, but make sure that the last one doesn't have a comma. 95 00:06:25,830 --> 00:06:28,170 Use double quotes, not single quotes. 96 00:06:28,650 --> 00:06:31,410 Booleans must be in lowercase. 97 00:06:31,410 --> 00:06:33,990 Boolean is basically is it true or is it false? 98 00:06:33,990 --> 00:06:36,810 So when you write true, it must be lowercase or false. 99 00:06:36,810 --> 00:06:41,580 It must be lowercase in Python, which I'll show you later in the course. 100 00:06:41,580 --> 00:06:43,200 It has to be true with uppercase. 101 00:06:43,200 --> 00:06:46,980 Now don't worry about learning python code for the exam once again. 102 00:06:47,950 --> 00:06:50,740 Now it's all very good and well, me showing you the stuff with PowerPoint. 103 00:06:50,740 --> 00:06:52,570 But let me show you this practically. 104 00:06:52,600 --> 00:06:57,670 You'll be able to download this PowerPoint presentation so that you have access to the details. 105 00:06:57,850 --> 00:07:03,280 So just click on the attachments to this course to get hold of this PowerPoint presentation. 106 00:07:03,460 --> 00:07:07,630 But I want to show you this practically, because it's going to be a lot easier to demonstrate this 107 00:07:07,900 --> 00:07:13,090 on a live Cisco device rather than just showing you the stuff with PowerPoint. 108 00:07:13,690 --> 00:07:18,460 Now, the great thing is that definite have a nexus always on sandbox. 109 00:07:18,490 --> 00:07:25,030 You can simply switch to the sandbox and you'll be able to try commands, which I'm going to show you 110 00:07:25,030 --> 00:07:25,660 right now. 111 00:07:25,870 --> 00:07:31,690 Now, on a mac, I'm going to use this command, but on windows you could use putty as an example to 112 00:07:31,690 --> 00:07:32,350 connect. 113 00:07:34,070 --> 00:07:34,340 Okay. 114 00:07:34,340 --> 00:07:35,850 So I'm going to copy this. 115 00:07:35,870 --> 00:07:37,160 Open up a terminal. 116 00:07:38,110 --> 00:07:40,490 I'll make this big to make sure that it's clear. 117 00:07:41,920 --> 00:07:45,470 And I'm going to paste that command in. 118 00:07:45,490 --> 00:07:55,240 So basically, I'm switching to Port 81, 81 using this username, and this is the DNS name of the router. 119 00:07:55,330 --> 00:08:04,750 I have to put my password in which is admin underscore one, two, three, four, exclamation mark or 120 00:08:04,750 --> 00:08:05,840 bang if you prefer. 121 00:08:05,860 --> 00:08:08,210 So there's the password. 122 00:08:08,230 --> 00:08:09,350 There's the username. 123 00:08:09,370 --> 00:08:10,480 This is the port. 124 00:08:10,510 --> 00:08:12,460 This is the protocol we need to use. 125 00:08:12,460 --> 00:08:14,140 And this is the domain name. 126 00:08:15,520 --> 00:08:15,610 Okay. 127 00:08:15,670 --> 00:08:17,050 It's complaining about my password. 128 00:08:17,140 --> 00:08:18,250 Let's try that again. 129 00:08:21,770 --> 00:08:22,040 Okay. 130 00:08:22,040 --> 00:08:26,060 So I've successfully logged in to this Nexus box. 131 00:08:27,080 --> 00:08:29,030 Hosted by Cisco Dev Net. 132 00:08:29,920 --> 00:08:30,510 Cisco Dev. 133 00:08:30,520 --> 00:08:35,200 Ned have made things so much easier because you can practice this stuff, you can try things using their 134 00:08:35,200 --> 00:08:36,130 free labs. 135 00:08:36,820 --> 00:08:44,260 Now on a Windows computer, you could use putty and switch to Port 81, 81. 136 00:08:44,260 --> 00:08:45,340 So S-H. 137 00:08:46,370 --> 00:08:52,460 Hostname is specs index OS management. 138 00:08:53,780 --> 00:08:57,590 Dot Cisco dot com and I can click open. 139 00:08:58,740 --> 00:09:00,930 You have to accept the public key. 140 00:09:00,960 --> 00:09:02,250 So I'm going to say yes. 141 00:09:03,350 --> 00:09:07,320 Login as admin admin underscore. 142 00:09:07,320 --> 00:09:10,890 One, two, three, four, exclamation mark or bang. 143 00:09:11,370 --> 00:09:12,320 And there you go. 144 00:09:12,330 --> 00:09:13,170 I've logged in. 145 00:09:13,650 --> 00:09:15,150 So show version. 146 00:09:16,830 --> 00:09:20,250 This command shows me that this is a nexus device. 147 00:09:21,420 --> 00:09:22,650 We can see. 148 00:09:23,680 --> 00:09:26,110 Various information about the device. 149 00:09:26,110 --> 00:09:29,200 We can see it's a 9000 V chassis as an example. 150 00:09:30,500 --> 00:09:36,770 So I'm going to jump back to my Mac and do this on my Mac show version on the Mac will show the same 151 00:09:36,770 --> 00:09:37,820 kind of information.