I have one.
So in the last video we saw that once we clicked here and we hit the end point at slash by then we received
this Jason here and I told you it's OK if you don't understand what Jason is for now.
And we'll explain it later.
It is so this is the video now.
So what exactly is Jason.
Well Jason is basically a minute that is used for data interchange between browsers or between servers
and browsers or between computers.
Even so what does that really mean.
Well think about when when when we started here on the road slash bike ride or think about when even
access any any normal pitch so let's just open here a long comment so we can discuss it here.
Just think about when your browser tries to access Google so your browser sends a request to google
doc and then it gets the response back.
Which is basically the index that H.A. page from Google that has the Google structure in it.
Right.
But if you think about it browsers can only convert or communicate using only text.
So for example I can't send an image from one browser to the other you just use the image.
In other words all communications all this is a very important point of communications right between
servers to server or between server to browser or even between browsers to a browser.
That's possible.
All communication on the internet can only be done in text.
OK.
So we cannot cannot send images.
We can send representations of image in text but we can't send images we can't send videos.
We can't we can send representations of videos in text but we can't send the video as and format because
the Internet as a whole depends on a protocol called TCAP.
Now TCAP only supports text.
We can't send a video to each other.
So whenever you see an image in an in a page or two ways this can happen one way is well this image
is basically you can think of it as a two degree ride.
So to a degree and then end inside this we would have something like 1 2 3 1 2 5.
And this number then for example 1 2 6 1 2 7.
Let's fill in a few more 4:59 here.
1 2 6 and 7 all these.
What are these numbers.
So these numbers are the RC value of the pixels.
So this image here would be a two by four so immense so very small image two by four pixels very very
tiny.
And each of these pixels has this value.
So in other words we've represented this image in the text format.
Similarly for video soonly for everything that you see right anything on the internet.
If we can if we want to to send it from one place to the other it has to be in some form of text right
now.
The idea is what form of text right.
We OK we will now establish that which you want to send something from my server to your server or from
my server to your browser as a response.
It has to be in text format.
It can't be any other format.
Now the question is OK what if it's text.
What kind of text should I just return to you just like we did in the first video return.
Hello world.
Just like like that.
Hello world.
Or should it be any in another format where it's easy for me to send it to prepare the response for
you and send it.
And it's easy for you to to receive this response.
Understand what it is without having to do like lots of computation just instantly understand what it
is and then replied.
So of course it's later when we want to find a format of communication between the two servers or between
one server and a browser or a browser to a browser.
We want to find a format that is easy to understand and easy to produce.
And this is what Jason Jason is a format that is used for the data and to change from one browser to
the other from one browsers server.
So.
So what how does Jason really look like.
So in the last video we saw a very simple example we saw we saw something like Field 1.
I think it's still here in here.
So it's field one says Let's just copy this one here instead just reading it again.
OK.
So Jason basically is made of many fields.
Each field has a name and a value.
OK.
So here the field is called Field 1 and its value is the string ABC.
After you're right one field and gets value they're separated by a semicolon here and after you're right
you add this comma.
So you say OK I'm done with the first field.
Now the second field it's called Field 2 and they should have different names field too and that is
value to the string.
Now since this is the last field I don't have to put a comma here but if I put it still fine but usually
a convention is we don't put it.
So you might be wondering OK that's that's an easy easy format.
So what are the tricks here.
What for example can I send here in this valley.
Right.
Because this trend could be anything I can say.
This is the name of my field.
So this entire string over here is the name of my field.
So you can have spaces it can you know it can pretty much be any English alphabet letter.
Really there are a few exceptions but I don't think most people would put like Slash something or are
inside the name so just make sure it's it's usually you know underscoring you're fine.
Dashes are fine spaces are fine but just don't put in like weird Dashon or like.
Or these forward slashes characters because they might mess up some things.
OK.
So for example I'll leave this field even field space one.
Now what values can I send here.
Well here I'm sending a string right.
A string is basically between two quotations.
But what else can I send right.
What other things can I send.
Well I can send a number so I can put here.
Sorry.
Well that means actually it's Adam does some highlighting here.
But since we are inside a comment it won't appear so three.
OK.
So I can send a number I can send a string to ABC.
What else can I send.
This field.
Well you can send a true or false.
So boolean true.
And be careful because this is not always supported in all our packages or in all browsers.
So you should be pretty you know some brothers think it's true like that you should be pretty careful
about that.
True or false.
Or stuff like that.
You also have to know in it.
But also again not all browsers support it.
OK.
So now you said we have three as a Nungarrayi we can send numbers.
We can send APCs and we can send also send booleans in some cases it's better of course if you just
replace this as a 1 or 0 and then you can do the parsing when you receive this Jason.
OK so let's just leave this one for now.
Now what else can we send.
Well we can send arrays.
So this is a bit tricky right.
I send an array and then and for now I'm just going to write an entry.
Now why can I put inside this array.
Right.
We will start with that if you want to send an error.
Let's say I want to send an array of numbers and I can put one two three four and then I've done what
if I want to send another area.
One two three four and ABC is still fine.
So I can basically send an array of objects and what else can I do.
Well you can also send arrays off objects so we can say array of objects and inside of this array of
objects I can insert other objects.
So what I mean by other objects is I can extrude other adjacent elements.
So think about this.
For example let's say I have another adjacent as a ago I'm right.
And then one two three.
So I can insert this Jason field inside the array here so I can have nested arrays.
So how does that work.
Well you see first of all the convention is we don't write an array on the same line because that would
be.
You can already see here that it's very nice x number is it's fine but if I have to to write lots of
fields for example field to 1 one and then you know it gets messy very quickly so usually the convention
is when you open the array click enter.
So we we we ran it among multiple lines and then here I would I want to make a new object.
So I write I open and close the curly brackets and then I say OK so Fiamma the one is that's totally
different.
Feel the wind and want for example.
Now once I'm done with the first object then I can write another object.
So again we do the same thing this time to then this is a string.
For example now.
So here what we've done is we're basically done an array of set offs off object.
Now what else can we do.
You can also do an array of nested arrays.
So that's a bit tricky right.
That's so we have to put a call here because we're not done yet.
Right.
This is a new field which is going to be an array.
So first I open and close the series and then inside it I'm going to have a nested array.
And I'm going to open and close another parentheses and then I'm going to have another nested object
inside.
So for example field one.
And then when there's no one name and for example name.
So we have here and array which has inside of said Field.
OK so this is a bit tricky right.
I got confused here.
So we have an error rate right.
So we should tap this here and then this nested array is going to be inside of the object right.
It's a bit tricky here.
Even I fell for it.
So here let me stab this and tap this object and then.
Yeah.
OK.
Right.
OK.
So now I should be fine.
Let's just tap this element one more time.
Make sure you're a bit ahead and should be fine.
OK.
So let's let's let's be very careful here with the way we have an array of objects.
So this is the first object in the area in the outer array.
And inside this object it has a field called nested array.
Which is an array of objects.
And the first element in that nested array is this object and it's called Field 1 and has two fields
so it has field line and name and then each of them has a value.
So it's very very tricky.
You're right and also and in the outer arrays so that's why that's why the vse this notation where you
start with one here and close with one here is very useful because it helps you keep track of what what
the scope are you in during the construction of the Jason OK.
So now that we know what Jason is let's go back to flask case let's delete all of this.
Let's go back to flask.
So last time we sent a very very simple Jason.
Right.
So this time let's make it even more complex.
Jason.
OK.
So we're going to make a name Jason.
I'm going to call it my name.
And then we're going to have age let's say 22.
So this is the numbers I need that is a number.
And now let's say I know I'm someone who has many phones.
So I'm going to have phones and then these phones are going to be an array.
So I'm going to open an array.
And then let's say this is the first object which is the first phone.
And then I'm going to have another field phone name that I know I Phone 8 maybe no phone number.
Let's say you know 0 1 1 1 or 0 or 1 1 1 1 1 whatever.
Let's copy this here.
Let's say we have another for I have another phone here which is you know a Nokia phone number is 1
1 1 2 1.
OK.
So now I have many phones.
It's an array of objects for each object has a field and a value.
And let's make sure that the colors are correct.
So no problems here with the commons.
If you want to leave a comment here it's fine.
But the convention is usually don't leave a comma in the last place.
And let's say first and see what happens.
So first go Clear and then flask run and then we're running the server now.
Now this this look this here is located at.
Slash my.
So let's go to our browser and go to slash by and you ok was changed to raw data and you'll instantly
see that this is our Jason has aged 20 22 name and you'll see that actually it has changed.
The order has changed a bit.
It's fine.
Usually the Jason F-I function can do that.
Don't worry about it.
That's that's totally fine.
And then these are basically our object.
Now here's an interesting thing.
How did we generate this.
This is basically a Norwan map in Python.
But we've generated Jason from it.
So how did we do that.
And we use a function called Jenna Jameson which is in flask.
It's built in flask from flask import juice on I so I'm gonna make AJ signifies something and then we
come here and return the Jets on the fly off this object.
Now this country is very useful because you can usually not only as you satisfy a map but you can certify
any object which is serial.
And we'll talk about that later in later years.
But this function is super useful when you're debugging something when you want to know the values of
some some object or something like that.
OK so this is basically what Jason is all about.
It's basically a format that is used to transfer data from one server to the other one browser to a
server.
Whatever.
Whatever the means of communication is two endpoints of the communication and we use it to transfer
this information here.
And as you'll see later in the videos this is what our response to the user will be.
And we'll also provide him an expected output.
So for example hey man returned Jason that I'll give you back is going to be is going to have a name
field.
I don't have an age field is going to have phones field and then inside the phones field you're going
to have this many objects of type that.
And so you'll be expecting what the output is.
And then our our mission is to fill in these fields here.
So for example let's say Eirik I get a request at by right to you know to do to output an age which
is equal to two times you know.
So will do so let's go here and do age Z-code two times five.
And then when I'm preparing the return Jason I'm going to put here age.
So now instead of hard coding these these fields where are these values we're essentially going to do
some computation here to service the user and then see what he needs to fill in these fields over here
prepare them and then replied back to the user.
And then he gets this Jason and he's like oh thanks for doing all this computation for me.
And and that's basically the idea of an API.
So let's let's really say this.
Make sure no problems here.
Throw your own flask and then Frigo here now and then we'll see that the age is 10 which is basically
the computation that we did in the body of the function.
Ok so hopefully you now understand what Jason has why it's important.
Just think of it as a format of transferring information.
If you see here this is very organized we can see what information we're returning back and the user
in the same time can also see and parse it and understand what the output is.
So it's very easy for us to prepare for for our customer or our user to read.
So it's a very useful format.
So hopefully you got this idea.
Yeah and I'll see you in the next video.