Basic CRUD operations with JSON
Well, we have started learning CRUD operations with a database, but now lets us start a CRUD operation without any database. Just with Files. Back to basics. We will be using JSON format for CRUD operation with Python Programming Language.
- We will be using a JSON data file containing 200 courses (see course.json)
The JSON structure of course.json file will look like this —
Now to load the course.json file will simply use JSON built-in package with python. Code goes like this —
Let the CRUD operations begin.
- Read an Item from JSON file.
2. Create an Item and Write into JSON File
2.1 We also need to save the json_data to file so let’s write a function to save the file with updated json_data.
3. Delete an Item from JSON
4. Update Operation is also Much More Similar to Create Item.
There You go we get completed the CRUD operations with JSON
Complete Code —
You can find the complete code with Flask as Backend on GitHub.
Cheers.🥃🍾