I have a list of JSON file. I would like to remove a certain id. like I want to remove 3rd id and print get the json without this.
my json file:
data = [
{
"id": 1,
"name": "John Smith",
"email": "john@example.com"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com"
},
{
"id": 3,
"name": "Bob Johnson",
"email": "bob@example.com"
}
]
The output I like
data = [
{
"id": 1,
"name": "John Smith",
"email": "john@example.com"
},
{
"id": 2,
"name": "Jane Smith",
"email": "jane@example.com"
}
]
I wrote this data = [item for item in data if item["id"] != 3] but I want a easy way to do it and I want to do it using index.
>Solution :
For this can use del operator to remove a certain id by index:
del data[2]