Home > Back-end >  How to delete json data with python
How to delete json data with python

Time:04-07

My Data

how to delete

{
    "Custom_id": "T2OeAX",
    "Message_id": 961484039422902362,
    "Channel_id": 933037293147660358,
    "Role_id": 933174488382717952
}

in json file with python

CodePudding user response:

Assuming the JSON in your image is read into data_string:

data = json.loads(data_string)
[del(d) for d in data["DATA"] if d.get("Custom_id") == "T2OeAX" and d.get("Message_id") == 961484039422902362 and d.get("Channel_id") == 933037293147660358 and d.get("Role_id") == 933174488382717952]

CodePudding user response:

I think you can use del to delete an object. if there is any condition, you can find the position of the object and use the following command.

del yourJson["DATA"][i]

In the question the position is 1

del yourJson["DATA"][1]

I hope helpful to you.

  • Related