Skip to content
Advertisement

How do i remove a specific json value in python?

I’m making a playlist website that can create display and delete playlists and songs. I’m using a JSON file to store the data. The only feature that isn’t working is the delete song feature.

This is my JSON file

JavaScript

I’m using the ID of the playlist and the index of the song to locate it in the list and using that to also delete it. This is my “deleteSong” function:

JavaScript

When I run the function it deletes the song from the right playlist but pastes the last bit of the list and gets pasted to the bottom of the JSON file.

E.g.

JavaScript

Advertisement

Answer

I think your problem is with trying to read and write the file in one go, which can cause weird cursor issues.

Try refactoring your code to have two separate open statements like the following (untested):

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement