Placeholder Image

Subtitles section Play video

  • in this video, I'm gonna be going over Jason, which is one of the most important concepts that you can learn as a programmer or as a Web developer.

  • I'm gonna be going over what Jason is, why you should know it.

  • And all this in tax involved with Jason and the end of the video.

  • I'm going to go through examples of Jason, so make sure you stick around till the end.

  • Jason, also known as JavaScript object notation, is simply a data representation format very similar to XML or yammer.

  • It's used widely across the Internet for almost every single A p I that you will access, as well as brick and fig files and things such as games in text editors like GS Code and many, many other places throughout programming.

  • It's used because it's extremely lightweight to send back and forth due to its small file size.

  • It's easy to read compared to something like XML, since it's much cleaner and there's not as many opening and closing tags to worry about, and it also integrates very nicely with Java spirit.

  • Since Jason is just a super set of Java script, which means anything you write in J.

  • Jason is valid.

  • JavaScript.

  • So ingrates.

  • Nice to the job disappeared, which is used all throughout the Web for front and or back on devoid of applications.

  • Also, almost every single major language has some form of library or built and functionality to parse Jason strings into objects or classes in that language, which makes working with Jason data extremely easy inside of a programming language.

  • Throughout your programming career, you're going to use Jace on all the time, whether it's creating an AP, I consuming an A P I or creating CONFIG files for you to yout or for other people to use for your application.

  • Now that we understand what Jason is and why it's important, Let's dive into some of this in tax involved a Jason by starting by talking about the types that Jason could represent.

  • As we know, Jason is a data representation format, so we need to build to represent a certain data types within it and Jason Natively support strings numbers, and these numbers could be in any format, whether they're decimal numbers, whole numbers, negative numbers, even scientific notation numbers.

  • It supports billions which could be the true or false supports know which essentially stands for nothing.

  • A raise, which could be a list of any of the types that we've talked about.

  • Plus the next type, which is the final type of object.

  • An object is the most complex but most used type within Jason, and it allows you to represent values that are key value pairs.

  • So you give it a key and then a value, and that value could be anything of the other times we've talked about.

  • So straying number, bully, an array know any of those different types could be the value for a key.

  • So let's dive into an example of how to use Jason inside of a file.

  • The first thing that you need to do is to create a file with the DOT Jason extension.

  • At the end of it, that's dot J S.

  • O N.

  • At the end of your file, metal, create a jace on file inside of this Jason file.

  • What you do is you take one of the types that we talked about and you put that inside of the file.

  • So, for example, you could put a string, you put a number of bullion, whatever type you want inside of that file, and that's valid, Jason.

  • But if all you have is a single string or single number, it's really not very useful to have a whole file for that single input.

  • So what?

  • Most of the time, when you're working with Jason, you'll have either an array or an object as your top level of your file and the inside of that array or object.

  • You'll have other values, so it may even have other objects have other raised or even just individual values.

  • Just strings are numbers inside of that.

  • So it's taken example of a user object that we want to put at the top level of our Jace on file, which we're going to call user dot Jason to create an object we need to use opening and closing curly braces.

  • And then inside of that will put all of the key value Paris that make up our object and every single one of these key value pairs.

  • The key must be surrounded by double quote, followed by a colon and then the value for that key.

  • And then, if we have multiple key value pairs, we need commas separating every single one of our key value pairs similarly to how we would create an array in a normal programming language.

  • So, for example, if our user has a name which surround that name, key and double quotes, put a semi colon after.

  • And then we'll put the value of our name inside of double quotes as well, because the string and it must be in double quotes.

  • And then the end of that, we'll put a comma because we have other key value pairs for a user.

  • For example, if we wanted to use a favorite number as another property, we'll put favorite number in double quotes, followed by a semicolon, and then put that users favorite number.

  • Then, if we wanted to use a Boolean, we use a comma and then another property.

  • We would use his programmer as Archy put a colon, and then we had put either true or false with no quotes around it, to signify that this is a Boolean and not a string.

  • So we put true or false, depending on if that user was a programmer or not, we could then go down and use hobbies as our next devalue pair.

  • So put hobbies and double quotes semi colon.

  • And then to creating that ray we use opening and closing square brackets and inside of the array, we put whatever type of value we want.

  • And in this case, we're just going to your strings for the different hobbies.

  • So we'll put those strings inside a double quote.

  • Oh, put commas between each one of them because we put commas between all the values in an array or writing out Jason.

  • Next we could have another property that will be an array of friends.

  • But instead of putting strings inside of this array, we're going to put more user objects inside of that array so we can put different user objects inside of that ray.

  • And now we have nesting of a raise with objects.

  • And that's how you really get into the power of Jason, where you can start to deeply nest different properties and really show a hierarchy of data as opposed to just a flat form out of data, like most data format files give you.

  • So, for example, for this friends of Ray, we could have a friends of rage, and it could have the same properties of name favorite number is programmer hobbies and even friends inside of that, and you can start to get a very deeply messed it over gray.

  • If you really wanted, then we just have to make sure that we don't put a comma on the very last property value.

  • Keep air that we have close it with a curly brace.

  • And that's our full Jason file created.

  • Now that we understand what Jason is and this in tax involved with writing Jason, I'm going to jump into a live example of me writing Jason file and then parts in that file in Java spares.

  • So I have visual studio code open and I'm inside of a file called cos dot Jason.

  • We're going to store an array of different companies, and each of these companies is goingto have a name, number of employees, a CEO and their rating out of five.

  • So let's get started by using arson text for creating a rate which is using opening and closing square bracket and inside of this array, we're going to store different objects.

  • So our first object is going to be our first company, which, as we mentioned, has a name and we're just going to give that company name of Big Corporation.

  • And then we put the calm at the end of the road.

  • We want to give it a number of employees as well.

  • And then this number of employees for this big corporations were going to say that they have 10,000 employees.

  • Then we want to give them a CEO and their CEO.

  • His name is going to be married.

  • And then, lastly, their rating out of five stars, it's going to be a 3.6.

  • And now we want to store a second company in this array.

  • So we just put a comma at the end of our first company object, open up a new object and then give it the same properties.

  • So we'll say your name and we're just going to get this one.

  • The name of small startup go down to the next line.

  • We got a number of employees.

  • In this case, they're just going to have three employees, too, since we're a small company, CEO is next, and this company does not have a CEO because they're so small.

  • So we're just going to put no here, which is okay to have different types inside of your Jason object because Jason doesn't care what types you're different keys are.

  • They just matters that you have keys and values.

  • So we have no here.

  • And then lastly, we're going to give them a rating.

  • Make sure you put that double coast, and their rating here is there's going to be 4.2 or 4.3.

  • And there we go.

  • That is our entire cos dot jace on object.

  • And as you see, we have no errors.

  • But if we, for example, didn't put the quote here, you see that we get an error and that's because we're using V s code and it tells us when we have errors instead of our Jason.

  • So we know that our Jason is always going to be correctly formatted, just like this is here.

  • Now it's looking up this index dot html file here, which is just a super simple file that has an opening script tag that we can put some Java script in here to run our page.

  • So what's creative variable?

  • We're just call it cos we're going to copy everything from this cos dot Jason because, as I mentioned at the beginning of the video.

  • Jason.

  • Anything in Jason is valid Java skirt so we can take this Jason directly just pasted into our company's variable.

  • And then if we go down here well on the company's variable, and we checked that out inside of our browser here.

  • As you can see, we have walked this company's variable, and we have both parts of our ray.

  • We have CEO name, number of employees rating.

  • And all of this is the information that we have in this file here that we copied over into our job script file.

  • Yes, anything.

  • Now here we have another company, but most of the time when you're dealing with Jason, they're going to get it back as a string and not as an actual job script object.

  • So to emulate that, what's around this and tactics.

  • So it's an actual string.

  • And if you say that you see that now our council, it just has a string instead of an actual object, and we can actually use this object inside of our job is curved.

  • So in order to convert this J some string into a JavaScript object, we need to use what's called jayson dot parts So if we go down to our log and we say Jason dark parsed, we pass it in a string, it'll take that string and convert it into a Java script.

  • Object.

  • So now, as you can see in here, we have our JavaScript object that we created from this string here, using jayson dot parts to get a choice on object right here.

  • And we can use this inside a job script, for example.

  • We wanted we could get the first company inside about of Ray.

  • We could get their name.

  • Now, if we say that you'll see it prints out the first company's name.

  • Second company's name prints it out and so on.

  • And you can do anything that you could do with a normal job.

  • Scared object to this newly part Jason object that we created with jayson dot parts, So I hope this baby was useful for you.

  • As you can see, the actual format for Jason is fairly straightforward.

  • You just have to mostly remember to use double quotes around all of your different keys, because in Java script you don't need the double quotes.

  • But in Jason, you do need these double quotes, other than that.

  • It's very straightforward.

  • It's easy to read, which is great, because just looking at this you can tell what it's representing and you can tell what the different keys and values mean.

  • And it's extremely lightweight.

  • So when you send it across the Internet through different AP eyes, it'll take up very little amount of space, which means it will quickly send back and forth, which gives your user a great end experience.

  • So thank you guys very much for watching you now.

  • Know everything you need to know in order to use Jason and consumed Jae Sung in your future projects.

  • If you guys enjoyed this video, please extra leave mia like down below, letting me know and subscribe for amore tutorial somewhere to this Thank you guys very much for watching.

  • Have a good day.

in this video, I'm gonna be going over Jason, which is one of the most important concepts that you can learn as a programmer or as a Web developer.

Subtitles and vocabulary

Click the word to look it up Click the word to find further inforamtion about it