Hello folks! I recently started my Python journey and came across Python's JSON Module while making a simple CRUD operations project in python. So, I thought of sharing my learning regarding JSON in today's article.
What is JSON?
JSON stands for JavaScript Object Notation. It's a lightweight and human readable data interchange format. Because it isn't tied to JavaScript, it can be used with other programming languages as well (like I used it in Python).
How does JSON look like?
A JSON object is a list of comma separated key-value pairs enclosed within curly braces.
For example :
{
"name":"divyanshu",
"language":"python",
"hobby": "sleeping",
}
In the above example, "name", "language" and "hobby" are keys, while "divyanshu", "python", "sleeping" are the corresponding values**.**
What is JSON array?
A JSON array is an ordered collection of JSON objects.
For example :
[
{"name":"Motu","fav_food_item":"samosa"},
{"name":"Patlu","fav_food_item":"jalebi"},
{"name":"Dholu","fav_food_item":"vada"},
{"name":"Bholu","fav_food_item":"kachori"}
]
Can JSON handle strings only?
No. JSON can handle other datatypes as well like numbers, booleans, null, arrays and objects.
For example :
{
"name":"tom",
"species":"cat",
"ears":2,
"eyes":2,
"is_famous":true,
"fears_spike_bulldog":true,
"hobbies":["chasing jerry","drinking milk","sleeping"]
}
Where is JSON used?
API communication : for data exchange between applications and APIs
Data storage : for storing data in configuration files and databases
Data exchange : for exchanging data between different systems or applications
Hope you found this article on JSON helpful. Happy coding😄!