I have a Python application where the user can insert a name and one or more extensions, the final result looks like this:
{
"sets": [
{
"name": "first",
"extensions": ".exe"
},
{
"name": "second",
"extensions": [
".pdf",
".epub"
]
},
{
"name": "third",
"extensions": [
".mp3",
".mp4",
".wav"
]
}
]
}
I want to delete the entry with the name "third", and consequently the correspondent "extensions".
I have tried something like this:
def deleteJson():
lines = []
with open("sets.json","r") as json_file:
for line in json_file.readlines():
j = json.loads(line)
if not j['name'] == "third":
lines.append(line)
with open("sets.json",'w') as json_file:
json_file.writelines(join(lines))