Posts

Showing posts from June, 2022

How to Handle JSON file in Python

Image
Normally in Python, We use several data types to store data such as Lists, Tuples, Sets, and Dictionaries. But If we want to add something to the data through user input, We can add and view only while running the program. If we stop the program and run again we loose what we add earlier. To give a solution to manage the data permanently, there are various ways. Today we are going to see how to handle(store, add, remove, read) a JSON file in Python 1. Read a JSON File Let's create a file called data.json as follows, data.json JSON is an object which includes key-value pairs. In my example, biodata  is a key where a list is a value for that key. The list contains two dictionaries(Objects). Let's create a file called  data.py  as follows, data.py I have imported json first. Then only I can use json object I have open my json file(data.json) with "r"(read) mode and assigned to a variable called f If I open on read mode I can only read the file, can not edit the file Loa...