I want to delete json objects if value found in the json body. Please see below code and json body. I tried in python but getting error : [TypeError: list indices must be integers or slices, not str]
import json
import sys
key = ['1']
myData = [
{
"id": 1,
"modifiedBy": "admin",
"fields": {
"Application": "1",
"Endtermin": 23011990
}
},
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]
# delete json objects.
[x for x in myData['fields'] if x["Application"] != 'key']
For example : In the json body, I will look for the Application value, when matching with key, then I want to delete json objects. Here i want to delete first json objects because key value is matching with Application value.
My results looks like here.
myData = [
{
"id": 2,
"modifiedBy": "admin",
"fields": {
"Application": "2",
"Endtermin": 11021990
}
}
]