Learn JSON Step-by-Step from Scratch

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
Hello and welcome to this session in this the session we are going to learn what is JSON and why it is used was it is used for and we will also see a very basic demo this is going to be very easy and very interesting I will start from scratch and if you have never understood JSON or if it is the first time you are hearing this word do not worry after this video you will know everything about JSON and we will go from scratch and I will go up step by step let us take an example let's say we have two machines or two computers and they want to talk to each other or exchange data the first computer says I can work with two programming languages Java and Python how many languages can you work with the second computer does not understand this way of communication so this first computer says lets design a common syntax a structural formatted way of representing data so that all computers can understand it and the second computer has no idea what is going on So the first computer designs a formatted way of exchanging data so we have two curly braces here then we have a Tag for languages and then a square bracket start and stop then we have the first data set that is the information about the first language within curly braces and then we have the second data that is the information about the second language and now this is a very well formatted and a very well structured way of representing data and our second computer understand this and he responds back with the languages he can work with now this way the two computers are able to communicate and also exchange data now this is a hypothetical example but the format of communication we just saw is called JSON JSON stands for JavaScript Object Notation and it is a way of communicating data with specific rules or a specific syntax and structure like XML and YAML JSON is another way of communicating data it uses key-value pairs and the syntax is taken from JavaScript that is why it is called as javascript Object Notation but JSON is portable with multiple languages so you can use JSON with almost all the languages now this information is coming from json.org which is the official website of JSON JSON is a lightweight data-interchange format it is easy for humans to read and write as we have just seen even humans can read and write JSON and machines can easily Parse and generate a JSON message or a JSON document and it is based on the subset of JavaScript language and that is why it is called as JavaScript Object Notation now JSON is built on two structures if we talk about the structure of JSON and once I show you a demo this will be even more clear but just to understand the basics these are the two structures a collection of name-value pairs and an ordered list of values a collection of name-value pairs is called object and ordered list of values is called array so these are the two basic structures in a JSON message or a document object and arrays and most of the programming languages use these two structures in some way or the other like object can be realized as an object record structure dictionary hashtable in programming languages and in most languages arrays can be realised as an array vector list or sequence and that is a reason all modern & most of the programming languages support these two data structures in one way or the other and therefore they can also understand and work with JSON now if I talk about object here an object is an unordered set of name-value pairs and it always begins with a curly brace and ends with the curly brace and then every name is followed by a colon and after every name-value pairs you will find a comma or the name value pairs are separated by comma let us see our example of languages here you can see we have languages and then we have these objects under the languages so here this is one object which is within the curly braces and then this is the second object so we have two objects in this JSON if we go to the array now array is an ordered list of values and hear it begins and ends with a square bracket and the values are separated by a comma if you look at our example on the right here languages is an array in this JSON and you can see it starts and ends with a square bracket and we have a single array in this JSON if we had multiple arrays we would have a comma after the end ] and we could have other arrays as well and we can also say that the languages array holds two objects in this JSON so these are two basic structures but there are other types we have already seen objects which is key value pairs and they can be strings or any numbers or any objects in this key value to the key is usually a string which is within quotes " " and the value can be a string which will come under quotes " " or it can also be a number so here we have age = 35 now 35 is a number so it is not in Quotes " " so these are the objects then we have Arrays there can be numerical arrays string arrays or any other object arrays then we can have strings in JSON strings will come under quotes " " then we can have numbers we can have simple numbers decimal numbers negative numbers or even scientific numbers we can have in JSON on we can also have Boolean types in JSON that is true and false or we can have null values in a JSON to this was about the JSON types now if you talk about very simple rules of creating a JSON the data is in name-value pairs, as we have seen, data is separated by commas { } hold objects and [ ] hold Arrays so these are the simple rules for creating a JSON message let us see a very simple demo so it will be very clear to you I am going on my Windows system and you can use any editor that can work with JSON like Visual Studio code here I am just creating a very simple text file I will say new and a text document and I will say this is demo and the extension I will give is json so here you can see I have created a simple file with extension as JSON now you can Open this file in any of the editors that can work with JSON I am using Notepad plus plus you can use Visual Studio code or any other editor and here I will create a very simple JSON document or JSON message so it will start with the curly brace and end with the curly brace inside this curly braces I will create an array so I will create a array for users and then I will give a colon and as we know it starts with the square bracket and it will end with a ] so now users is an array and we can now create data for this array and again I am going to use { here for the first set of data I will say first name and a colon and I will say first name is Graham and now for the second data I will give a comma here and then I will say last name and I will say this is Bell then again , and then I will say age and here I will say age is 30 so this is one data set or one object of this array now I can create multiple data on multiple objects and I am just going to copy this object and give a comma here and then paste it again so we have the second object I will say the first name is Isaac and Newton and I will give the age so now you can see here we now have these two objects in the uses array and this is a valid JSON now if I want to add more arrays like users is one array I will go to the end and give a comma here and let's just say I will create One More array called subjects and again I will give a colon and then square bracket start and a square bracket stop and inside the square [ ] I can give my objects within curly braces { } so here I will say name and colon and the value is let us say automation and I can also give the ID to the subject lets say 1 then I can create one more subject here I will say name is JSON and id is 2 so here you can see this is a valid JSON where we have 2 arrays users and subjects users array has two objects and subjects array also has two objects now if I want let us say I want to add hobbies of the user I will say hobbies and then if I have to add multiple hobbies I can again given array here and I can say reading and then I can say , and writing and I can keep on adding the values here so here I am using an array for the value of this particular hobbies tag and then if i want to add something like friends of this user I will say friends and then I can use a array and within the array I can add objects so I can again say here I will give a curly braces start and stop so here I will say first name and I will say here Isaac and then I will say last name Newton so if you see here I can do nesting as well so here we can do nesting between arrays and objects like this and this is all valid and you can save this and here even I can give a subject ID for a user so all this will work this is a valid JSON and just in case you want to create a local JSON server or start a JSON server and run this and check on the browser you can do that as well and just in case you want to learn that you can go on my website automation step by step dotcom and here you will see a section for API mocking and how to mock API is if you go here this will take you to a YouTube playlist and on this YouTube playlist you can see how you can create a rest API for testing using the JSON server so using json server you can also run this JSON which is actually a you can say it as a rest API where we have added all this information so this is how you can very easily create a JSON and I hope now you know what is JSON why we use it and how we can create a JSON I hope all this was very useful for you I will meet you in the next session thank you for watching
Info
Channel: Automation Step by Step
Views: 63,889
Rating: undefined out of 5
Keywords: what is json, why do we need json, why is json used, json beginner tutorial, json for beginners, how to create json, learn json, json tutorial, how json works, json examples, json demo, json step by step, json by raghav pal
Id: 9t3vMi95z2w
Channel Id: undefined
Length: 13min 10sec (790 seconds)
Published: Wed Oct 28 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.