- [Instructor] As data is flowing back
and forth between our application
and our SDN controller, it needs to be formatted.
And there are different ways that we can format that data
but a really popular way is called JSON,
that stand for JavaScript Object Notation.
And the big goal behind having the JSON format,
is so that it can be readable by humans.
But even though that's the goal,
if we're looking at a really complex JSON dataset
where there's lots of nesting going on,
it could look a little bit intimidating.
And so our goal in this video is to simplify that for you.
We want to break to down so you can look at any JSON dataset
and realize it breaks down to just two simple structures.
The first structure is going to be called an object
and that's a collection of name/value pairs.
And we're going to have something else called an array
and that's an ordered list of values.
Let's talk about each one of these
and be able to recognize these.
First, let's consider the object.
The object is an unordered set of name/value pairs.
We've got a name, we've got a colon,
and we've got the corresponding value for that name,
it's almost like assigning a value
to a variable in programming.
And then we could haver a comma,
and another name/value pair,
and another comma,
and another name/value pair, and so on,
and they're in no specific order.
This is very similar to something
we're going to be talking about later when
we get into Python programming,
it's very similar to a Python dictionary.
And this object is going to be enclosed in curly brackets
as opposed to straight brackets.
Here and example, notice we've got in curly brackets
a couple of name/value pairs.
We've got a name of firstName,
and notice it's in quotes because it's a string,
there's a colon separator
and we've got Kevin,
another string so it's in quotes, that's the value.
The value of firstName is Kevin.
That's the first name/value pair.
Then there's a comma and we've got lastName,
again that's a string so it's in quotes,
and the value is Wallace, another string so it's in quotes.
And the name and value are again separated with a colon,
and it's all enclosed in curly brackets.
And by the way just as side note,
notice how I've used uppercase in these names,
I say firstName but the N in name is capitalized
but the F is not, the N in the lastName is capitalized
but the L is not, this is something
that programmers often use, it's called camel case.
It's where you're combining up multiple words
and when you combine multiple words,
not the first word,
but every other word begins with a capital letter.
So we're combining first and name,
well the F in first is not capitalized
but the N in name is.
Again, that's called camel case.
Now as we look at this collection of name/value pairs
we've only got two pairs so it's not
that difficult to read,
but to make it more readable you typically see this written
with more whitespace.
And what I mean by whitespace is
we'll probably have our curly brackets on their own lines.
And we'll have each of our name/value pairs on
their own lines.
Now we still have the comma separator,
notice after firstName, colon Kevin,
there's a comma after that
so we still keep the same syntax,
we're just inserting additional whitespace
to make it more readable.
And again, that's an object,
that's one of two data structures that JSON uses.
The other data structure is called an array.
An array is an ordered set
of comma-separated values.
And these are enclosed in straight brackets
as opposed to curly brackets.
Here's an example, here are some certifications
that Cisco has, and these are string values
so they're enclosed in quotes,
but I've got CCNA in quotes, comma,
that's the first value.
CCNP Enterprise in quotes, that's the second value
and another comma,
and CCIE Enterprise Infrastructure enclosed in quotes.
That's a third value.
This is very similar to something
we're going to be seeing with Python programming later on,
called a Python list,
and if we were to insert whitespace here,
it's going to look something like this.
We're going to have the straight brackets on their own lines
and each value is going to be on its own line.
Again, we still have a comma separator.
Notice after CCNA, there's a comma,
after CCNP Enterprise, there was a comma,
and those are the two different data structures we have.
So why is this so complicated?
Well, I've shown you some very basic values,
but these values could be
something other than just a string.
It could be a string, but it could be a number,
it could be an object.
So the value of an object could actually be another object.
The value of an object or the value of an array
could also be another array.
It could be null, it could be a Boolean value,
like true or false.
And when you have a fairly complex
JSON data structure you're working with,
it might be a good idea to do a sanity check.
And what I mean by that is
you could put your JSON formatted data into a JSON validator
to make sure all your brackets
and commas and colons are correct,
because it's easy to make a mistake
and you can search online for a JSON validator,
but the one I typically use is jsonlint.com.
Let's go into that website
and let's do a quick validation.
All right, we're sending it jsonlint.com
and let me just paste in an example that we had earlier.
This was an object.
We had the name of firstName,
and it had a value of Kevin, separately by colon,
we had a name of lastName
and a value of Wallace.
Now notice this does not have any whitespace in it,
but if you say validate JSON, not only will it come back
and let us know that everything is correct,
it's going to put in whitespace to make it more readable.
So take a look at this.
Now we've got the curly brackets on their own lines
and each name value pair, is on its own line.
So no matter how complex our JSON data structure might look,
remember, it just breaks down into two data structures,
an object, which is a name/value pair,
and an array, which is an ordered list of values.