In this video, we're going to discuss JSON or JavaScript object notation.
Why is this important?
It's important because in the CNA blueprint there's a section under automation and programmability.
6.7 Interpret JSON encoded data.
This is something that you need to know for the exam.
So make sure that you watch this video and that you understand, Jason.
Okay.
So let's start with why you've probably seen one of these before.
Are you a human or a robot?
Now the reason we have CAPTCHAs is because machines struggle with unformed data.
If the data isn't clear, machines will struggle to interpret the data.
JSON is a way to format data.
It's also a way to send data from one machine to another.
We as humans can interpret data quite easily, especially if it's slightly off.
So as an example, if you type show version on a Cisco iOS device, so let's say classic iOS, the output
will be different to a Cisco iOS X device, which is different to a Cisco Nexus device.
The output will vary slightly.
Now, that's not a problem for us as humans.
We can make adjustments for the slight changes in the output of the data, but machines struggle with
that.
So we want data that is consistently formatted properly so that machines can communicate properly.
As an example, if I switch to a switch using Python, so I connect to the switch using Python and type
show IP route or show version.
If I'm not using a JSON format, so the output is not formatted in JSON format or another format such
as XML or YAML, it's difficult to write code that can interpret the data properly.
Now, if Cisco once again have made things easier using pirates, so if you use pirates rather than
say net mico to connect directly to a device using a Python script, the output comes back in a format
that's easy to interpret using a Python script.
But if you're using pure net mico or pure telnet and you simply typing show version and you're trying
to pass that output, it's very difficult to write good python code to pass the output, number one,
and secondly, to handle a situation when the output changes.
So you upgrade the router as an example and the output formatting is different.
Your python code will struggle to interpret that.
So for machine to machine communication, it makes sense to use standard output and it makes sense to
have a format that's easy to interpret, especially for machines.
So to help us with JSON formatting.
Let's start with a Tesla.
Okay.
I'm going to ask you some questions about this Tesla.
Well, first question is, who's the manufacturer?
That would be Tesla.
What type of model is this?
Model X.
Notice how I've formatted this data manufacturer, Colon Tesla.
This is known as a key and this is known as a value.
So we've got a key value pair.
What is the model?
It's model X color, white fuel, electric miles per gallon.
City 99 miles per gallon.
Highway 93.
Now I've simply pulled this information off Google.
Hopefully it's correct, but don't get hung up about the data.
Look at the format of the data.
Again, we have what's called a key separated by colon, and then we have a value.
You need to understand JSON formatting.
That's an example of JSON formatting.
It actually looks like this.
We have to use double inverted commas.
So it would be something like first name Colon, then David as an example.
So JSON data is written as name of value pairs.
So going back here, I said key.
It could be also referred to as a name.
So name value pair.
Another example is last name and a value name.
Value pair consists of a field in double quotes followed by a colon followed by a value.
Make sure you understand that format.
Now for the exam they are two JSON data types that you need to know objects and arrays.
Let's start with an object.
So adjacent object would look something like this.
Notice we've got curly braces.
Data is surrounded by curly braces and it's an unordered collection of key value pairs.
So here's our key first name, David.
A lost name, bumble notice, separated by a comma.
Make sure that you know the format so curly braces surrounds the data.
We've got key value.
The keys and values use double quotes, not single quotes.
Each key value pair is separated by a comma, except the last one.
Trailing commas must not be used.
Now it's going to be easier to look at it in this format, easier to read spaces or not important with
JSON.
So notice the curly braces.
First key first value.
Second key, second value separated by comma, comma.
Third key.
Third value.
No comma.
So if you put a comma here, that would be a problem.
Make sure once again that you recognize this format for the exam.
So just to summarize, a JSON object is an unordered collection of key value pairs.
In other words, this is not ordered.
It could be in any order.
Doesn't matter.
Surrounded by curly braces once again, key and value pairs are separated by a colon.
Spacers don't matter, but make sure that the last one doesn't have a comma.
Use double quotes, not single quotes.
Booleans must be in lowercase.
Boolean is basically is it true or is it false?
So when you write true, it must be lowercase or false.
It must be lowercase in Python, which I'll show you later in the course.
It has to be true with uppercase.
Now don't worry about learning python code for the exam once again.
Now it's all very good and well, me showing you the stuff with PowerPoint.
But let me show you this practically.
You'll be able to download this PowerPoint presentation so that you have access to the details.
So just click on the attachments to this course to get hold of this PowerPoint presentation.
But I want to show you this practically, because it's going to be a lot easier to demonstrate this
on a live Cisco device rather than just showing you the stuff with PowerPoint.
Now, the great thing is that definite have a nexus always on sandbox.
You can simply switch to the sandbox and you'll be able to try commands, which I'm going to show you
right now.
Now, on a mac, I'm going to use this command, but on windows you could use putty as an example to
connect.
Okay.
So I'm going to copy this.
Open up a terminal.
I'll make this big to make sure that it's clear.
And I'm going to paste that command in.
So basically, I'm switching to Port 81, 81 using this username, and this is the DNS name of the router.
I have to put my password in which is admin underscore one, two, three, four, exclamation mark or
bang if you prefer.
So there's the password.
There's the username.
This is the port.
This is the protocol we need to use.
And this is the domain name.
Okay.
It's complaining about my password.
Let's try that again.
Okay.
So I've successfully logged in to this Nexus box.
Hosted by Cisco Dev Net.
Cisco Dev.
Ned have made things so much easier because you can practice this stuff, you can try things using their
free labs.
Now on a Windows computer, you could use putty and switch to Port 81, 81.
So S-H.
Hostname is specs index OS management.
Dot Cisco dot com and I can click open.
You have to accept the public key.
So I'm going to say yes.
Login as admin admin underscore.
One, two, three, four, exclamation mark or bang.
And there you go.
I've logged in.
So show version.
This command shows me that this is a nexus device.
We can see.
Various information about the device.
We can see it's a 9000 V chassis as an example.
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
kind of information.