filmov
tv
42 How to read or Write JSON File in Python ?

Показать описание
Hey guys,
welcome to Free Tutorial TV and Python tutorial for beginner.
In this video I'm going to show you how to handle J Son values in Python.
So first of all what is J Son.
So J Son is a text format which stands for javascript object notation.
And J Son is a syntax which is used for storing and exchanging data.
Now if you want to know more about J Son what is J Son .and how to create J Sons and what value you can
store in J Son.
Then I have created a whole video about that. so you can watch that video and understand more about J Son.
So let's get started with this tutorial. and let's see how we can use J Son in Python.
So to use J Son in Python you use in built package which is called J Son. so you need to import this
inbuilt package which is J Son.
Now let's say I have a python dictionary . so let me create a dictionary in Python which have let's say.
So this is our dictionary in Python.
So in order to convert this dictionary into J Son you use this J Son keyword which we have imported
here and then call a method call dumps.
So this dumps Method.
We can call here to convert some Python values to J Son value. and we will pass this dictionary variable
A here.
And in order to print the value of J Son we can use this print Method.
So I'm going to enclose this J Son dot dumps Method.
Inside our print function.
Now let's run this code and you'll see that this J Son dot dumps function has converted your dictionary
into our J Son value.
So this is our J Son text format.
Now the next question which can arise here is what data type this dumps function takes as an argument.
So it makes our dictionary we already know now . but what are the other data types which we can parse
as an argument to this dumps function.
So it turns out that you can provide majority of your collections and your data types as an argument
to this dumps function.
So you can provide dictionary here . or list tupple a string and float or a boolean value and any value
you can provide here. I think sets you can not provide as an argument here but other than sets you can
provide any other format as an argument to this dumps Methods.
So let me show you how you can provide all of these values into this.
J Son dot dumps function.
So here in the first print statement I have provided the dictionary in the second print statement.
I have provided a list in the term we have provided table in the form statement we have provided the
string and then the integer and then followed values and then we provided that to boolean values false
and true.
And at last we have provided this none keyword to this dumps function.
So let's run the code and let's see what happens.
So everything runs fine.
So that means you can convert from this J Son dot dumps function a dictionary or a list or a tupple
or a string or decimal or a float or a boolean value into a J Son value and all these are valid
dates and values.
Now let me go once again to this dictionary Method.
And here also as just as values you can provide any type of values. which I have shown here.
So you can use inside this dictionary for example another dictionary .so I can just write.
so we can also provide a tupple here.
So let's run the scored and it's totaly valid.
So you can see our dictionary is now converted to J Son value.
Now this dumps function also takes few other parameters also.
So we can also provide a parameter called indent.
So you need to write indent is equal to and then after that you can write some number here.
So if you want to give the indent of four to each and every element of your J Son then you can write
indent is equal to 4.
And let me run the code once again.
And now you can see this J Son is printed the format and the indentation here . indentation
means this indentation is four spaces for each and every element of your J Son.
And so if you want to print your ideas into a pretty format then you can just write and indent is equal
to and the number of indents you want to give.
So let's say I want to provide just two and then here and let me run code once again and you
will see.
Now this only have two.
And then is for every element of this J Son.
Also you can provide a parameter called the separators.
And as the separators.
Let's say first value I want to provide here is our DOT value and the space here.
And the second value I want to provide here is this equal to symbol.
So what the separators argument does is it will replace your commas and that this dot notation and your columns
with this equals to notation.
**************************************************************************
please like and follow us in Facebook and Instagram.
welcome to Free Tutorial TV and Python tutorial for beginner.
In this video I'm going to show you how to handle J Son values in Python.
So first of all what is J Son.
So J Son is a text format which stands for javascript object notation.
And J Son is a syntax which is used for storing and exchanging data.
Now if you want to know more about J Son what is J Son .and how to create J Sons and what value you can
store in J Son.
Then I have created a whole video about that. so you can watch that video and understand more about J Son.
So let's get started with this tutorial. and let's see how we can use J Son in Python.
So to use J Son in Python you use in built package which is called J Son. so you need to import this
inbuilt package which is J Son.
Now let's say I have a python dictionary . so let me create a dictionary in Python which have let's say.
So this is our dictionary in Python.
So in order to convert this dictionary into J Son you use this J Son keyword which we have imported
here and then call a method call dumps.
So this dumps Method.
We can call here to convert some Python values to J Son value. and we will pass this dictionary variable
A here.
And in order to print the value of J Son we can use this print Method.
So I'm going to enclose this J Son dot dumps Method.
Inside our print function.
Now let's run this code and you'll see that this J Son dot dumps function has converted your dictionary
into our J Son value.
So this is our J Son text format.
Now the next question which can arise here is what data type this dumps function takes as an argument.
So it makes our dictionary we already know now . but what are the other data types which we can parse
as an argument to this dumps function.
So it turns out that you can provide majority of your collections and your data types as an argument
to this dumps function.
So you can provide dictionary here . or list tupple a string and float or a boolean value and any value
you can provide here. I think sets you can not provide as an argument here but other than sets you can
provide any other format as an argument to this dumps Methods.
So let me show you how you can provide all of these values into this.
J Son dot dumps function.
So here in the first print statement I have provided the dictionary in the second print statement.
I have provided a list in the term we have provided table in the form statement we have provided the
string and then the integer and then followed values and then we provided that to boolean values false
and true.
And at last we have provided this none keyword to this dumps function.
So let's run the code and let's see what happens.
So everything runs fine.
So that means you can convert from this J Son dot dumps function a dictionary or a list or a tupple
or a string or decimal or a float or a boolean value into a J Son value and all these are valid
dates and values.
Now let me go once again to this dictionary Method.
And here also as just as values you can provide any type of values. which I have shown here.
So you can use inside this dictionary for example another dictionary .so I can just write.
so we can also provide a tupple here.
So let's run the scored and it's totaly valid.
So you can see our dictionary is now converted to J Son value.
Now this dumps function also takes few other parameters also.
So we can also provide a parameter called indent.
So you need to write indent is equal to and then after that you can write some number here.
So if you want to give the indent of four to each and every element of your J Son then you can write
indent is equal to 4.
And let me run the code once again.
And now you can see this J Son is printed the format and the indentation here . indentation
means this indentation is four spaces for each and every element of your J Son.
And so if you want to print your ideas into a pretty format then you can just write and indent is equal
to and the number of indents you want to give.
So let's say I want to provide just two and then here and let me run code once again and you
will see.
Now this only have two.
And then is for every element of this J Son.
Also you can provide a parameter called the separators.
And as the separators.
Let's say first value I want to provide here is our DOT value and the space here.
And the second value I want to provide here is this equal to symbol.
So what the separators argument does is it will replace your commas and that this dot notation and your columns
with this equals to notation.
**************************************************************************
please like and follow us in Facebook and Instagram.