In computing terms, what often people refer to JSON now is JavaScript object notation
So... It's a way of representing arbitrary data in an ASCII format that can be easily
transferred over the internet that can be stored on disk and things in a way they can be processed by most programming languages
Cool, end of video. Yeah
So, why do we need something like JSON? Computers are great at storing data and they're great at processing data. The problem with computers
and data is
The format of how data is represented is fixed by the program that's been written
it's fixed by the architecture of the machine that's doing it and if you try and transfer that from one machine
to another machine, if they're the same type and running the same software it will work great
But if you say got a piece of data that you've created on your Sun workstation and you try and transfer it to your
say... IBM PC or your Intel Mac?
Then there's a good chance that they will interpret the data in different ways
we talked about Endianness in another video as a classic example of how
Sometimes a computer store data in a different way to another.
So what JSON gives you is a way of representing arbitrary data structures
That are sort of free from the programs that are represent— that are representing them
XML does something similar, the "extensible markup language". The advantage of JavaScript is
It's lighter weight in some ways
and things although that's perhaps less of an issue because it can always be compressed but
It helps but also obviously if you're processing it on the web in JavaScript, JavaScript object notation uses the same parser
as JavaScript as a programming language.
So what does JavaScript object notation have?
The two main things it may have is an object
which will map a string to some sort of value
And Brian Kernighan had talked about this in another video where he covered hash tables
it's exactly the same sort of thing.
So we can have a
Object and they're represented by a curly brace and then we have the string
so let's say name and that maps to a value and let's have another string that says Shawn and then we can have another
key in there, let's say birthday and that maps to
Let's just put 42 there, and so on
And we can have as many of these as we like. This value we can have here can be any
other JavaScript thing so it can be a number it can be a string
It can also be another object. So we could have something that says
"children" and then that could be an object there which maps say the name of your children to some details about them
That works you can nest them like that, but children
Tend to be an ordered collection you tend to have them one after the other
So we also have the ability to represent ordered things using an arrays and then we can have a series of things there
So the difference between an object and array is an object maps a key to a value
whereas an array
specifies an ordered collection of things they have this idea that this one comes after this one. So they have a
numerical index and we specify an order. Objects don't have a numerical order. So in this case we would have
children, so the first one, let's call that one
Alice and then we've got another one. Let's call that one Bob and then he has a third one. I don't know
Let's think that one could be called... let's go with Charlie.
and you might have a fourth one, which would be called Derrick and the fifth one which might be called
Esmeralda and so on. So we can have an ordered collection of things and so we can build up
any arbitrary structure
And of course the thing to remember is that you don't have to use JavaScript to use this — JavaScript object notation to do this
But it helps and it's become very popular doing this as we said, it's lightweight
You can remove the white space and things and you can you parse it relatively simply and if you're doing in JavaScript
So it's become very common on the web but also to transfer data between any other sort of programs.
Here, we've said that your children is a list of
strings
We could have specified that they are actually objects. And so Alice could really, let's just push this on to another good paper
So we've got what we had before we've got kids
I guess gotta abbreviate and that maps to an array and this time we're going to have an object here inside the array
which has got a name which maps your name to Alice and then
that could also have what else we have in the object. We had a birthday,
again, I'm abbreviating... which you can't do in JavaScript. Because it would be a different key and we'll put that to be 56
And then of course
She could have some children or kids and then we'd have an array of more objects and so on
and then eventually that ends that object and then we could get around to
Doing Bob and so on
And so on like that, so yeah, you can build up complicated structures in that way. But mainly it's a file transfer format, yeah
Yeah, it's exactly what it's used for. It's used for transferring data
in a way that is pretty much
agnostic to the programming language being used because you can represent pretty much any arbitrary structure you'd like in there
Representing graph like structures where you've got links from one to the other would become interesting
It's not the only format. The structure of this is very very similar to the structure that's inside a PDF file.
It has dictionaries which maps
keys or names rather than the strings to values and it has arrays and so on so there are other structures a very very similar
but it's just become common to transfer these things over the web.
So the first one let's call that one
Alice and then we've got another one. Let's call that one Bob
How did you know my children's names?
we keep watching videos about them with Mike. Because it's fairly common and then we'll talk about
Differences with say one password what LastPass will do is it will produce a master password by a pet...