Hello every one i tried the following code, work best for deleting an object from the json file
#!/usr/bin/python
# Load the JSON module and use it to load your JSON file.
# I'm assuming that the JSON file contains a list of objects.
import json
obj = json.load(open("pandas.json"))
# Iterate through the objects in the JSON and pop (remove)
# the obj once we find it.
for i in range(len(obj)):
#path = ["000000000036.jpg","000000000049.jpg", "000000000077.jpg"]
if obj[i]["path"] == "000000000036.jpg":
obj.pop(i)
break
# Output the updated file with pretty JSON
open("updated_file.json", "w").write(
json.dumps(obj)
)
here i have a question what i suppose to do if i want to delete many random json objects from my json file i tried but fail please let me clear on it "help appreciate".
Assuming the json data is an array of json elements, the below code will remove 3 random elements from it. Customize it as per your need.