 Hi, welcome to this video session. In this video session, we'll be saying how to handle JSON text in Python. So let's also see what outcome has been planned for this video. So after watching this video, the audience or the students will be able to encode and decode JSON text in Python. So primarily this video would be a hands-off where it will show you how to encode a Python object into a JSON and how to decode a JSON string into a Python object. Let's move to the hands-off session here. And for this hands-off session, what we are planning is we are planning to encode and decode a Python object into a JSON text. So we'll move to, we'll switch to Google Collab and we'll see what are those methods and what Python modules we require to handle JSON text in Python. So let us switch to Google Collab. So this is a Google Collab IDE and on this Collab IDE, I have already a small data text cell where I have put the various JSON types available to a developer in a various Python types. So primarily we'll be saying what happens to this JSON type when we encode them into or when they are decoded into Python object. So we'll start with a code cell here. So here in this code cell, we'll first import a module which is necessary for my Python script to use methods which handle encoding and decoding of our JSON. So now to just to set the context very straight, when I say encoding, I would say how a Python object would be encoded into a JSON. And when I say decoding, I'll say how a JSON string will be decoded into a Python object. So let us move, let us take a small sample JSON string, we'll define a small JSON is here. So it would be an entirely string. So what we'll do is we'll encode them into, okay, since it's a JSON, let me encode everything into a set of two single codes. So let's have a JSON string code here. And what we'll do is we'll have some key value pairs here. So it's based on JSON syntax. Let's say a name is Peter and let's have one more key, JSON key here, I'll call it as A's and A's will be, let's say, 30. That's it. So we'll have a two small JSON string, which has a key and a value. And you can see that this value is upstream. And this value is of type numeral. Now I want to convert this. For example, let me also see what type of variable this is. So here, we put a string here, okay, if I enter this, you should see the type of this, it's executing, okay, that's a string which I'll say, and if I want to see what type of variable it is, okay, it's a string. So it's a JSON string. How do I convert that into a Python object? So what I'm saying is I'm decoding a JSON string into a Python object. Usually the JSON string, once you encode into a Python object, what exactly happens is it usually converts into a Python dictionary. So how do I do that? So sample I'll call pi object is equal to, now what method I need to use? The method to decode a JSON string is json.loadss for string. I need to provide this variable, same as json str, and once I convert, what I'll do is I'll print that object, and at the same time, I'll also print the type of that object as well, okay. So let's see this, what it prints. So it prints the following. You can see that it looks, it's a dictionary. So to verify that, we'll also print the type of that, let's say type. So you can see it's a sort of dictionary type. So what we have seen, we have seen a JSON string can be decoded into a Python dictionary object with the help of method json.loadss. So let us move to other code, where we'll here see how to convert a Python object, or how to encode a Python object into a JSON. Let's see that. So let's define a sample object, we'll call it a sample object. Let's call it a sample object 2. So sample object 2, this will be a dictionary. So here we need to define values, we'll use the same, the name is a string. So let's call it as once, let's queue, let's call it as Andrew. And let's take age as one more key field, whose value will be 45. And we'll take one more variable, and let's call it as, let's call height. And this I'll represent in floating point format. I'll call it as 5.10. And we'll just do a small print to ascertain. We have seen technically correct and it prints the contents of that. And we'll also print the type of that. We'll call this as type. You can see that it prints it's a dictionary. So now how do I convert that into JSON? So to convert that into JSON, we use a method. You need to provide the object, which you want to encode into JSON string. That will give you, I'll just call temp pair. And I'll print that temp pair as well. You can see that when I execute it, yes, it converts that and it prints it. So you won't be able to find much of difference in this output. So what we will do is I need to see what's the type of output, which my JSON.jump has, the dump has generated. So I'll put that in a type. So now you can see that in separator. So you can see that its type is str. So dump s, what dump s does, it actually encodes a Python object into a JSON string. And what JSON.loads does, it decodes a JSON string into a Python object. So this is it. Let's see, as a quick summary of this, let's see what. So based on the methods JSON.loads and dumps, the general conversion goes in this way. A Python dictionary object gets converted into a JSON object. A Python list into a JSON array. Python tuple will do get converted into array. Python str into JSON string. Python types of int and float, they do get converted into a number. And Python Boolean types, which are true and false, they convert into JSON Boolean types, true and false. That's how we write in JSON with t with lower case and f with lower case. And Python runtime gets converted to JSON runtime. So what have we seen in hands-on? In hands-on, as a quick summary of this video, in hands-on, we saw that we need to import a package called a JSON, which we do it with the help of line import JSON. And we have used two methods, JSON.loads and JSON.dumps. Loads is to decode a JSON string into Python object and JSON.dumps is to encode a Python object into a JSON string. So as a quick reflection of this video, the question is, a Python object having tuple of tuples will encode in JSON as what? So you can pause the video at this moment and you can watch the video to the point of pause and you can guess an answer for this. The answer for this question is, it gets converted into array of arrays. Why? Because we have seen that a tuple gets converted into array. So if we have a tuple of tuples, it should be an array of arrays. And there's a bibliography which I use for this video. You can explore these links for the study of the background material required for this video. So thank you and that's it for this video.