I have JSON file (test.json) that has a list:
[
{
"Action": "ADD",
"Properties": {
"Type": "New",
"Value": "List"
}
},
{
"Action": "REMOVE",
"Properties": {
"Type": "New",
"Value": "Image"
}
},
{
"Action": "ADD",
"Properties": {
"Type": "New",
"Value": "Text"
}
}
]
I need to iterate through the list and delete the key (item) that contains 'REMOVE' , i.e. item['Action'] == "REMOVE".
It should look like this after deletion:
[
{
"Action": "ADD",
"Properties": {
"Type": "New",
"Value": "List"
}
},
{
"Action": "ADD",
"Properties": {
"Type": "New",
"Value": "Text"
}
}
]
I use this to print the item. How do I delete the item?
with open('test.json') as json_data:
data = json.load(json_data)
for item in data:
if item['Action'] == "REMOVE":
print item