I have a json file with objects with the same ID. I have a results
list inside each. How to remove the entire object if results == []
?
I have a And I have a UnboundLocalError: local variable 'item' referenced before assignment
error.
JSON input:
[{
"objectID": 10745,
"results": [
{
"model": "AUDI - TT QUATTRO",
"price_str": "4 800 €"
}]
},
{
"objectID": 10745,
"results": []
}
]
My code:
for item in data:
objectId = item["objectID"]
results = item["results"]
def removeDuplicate():
if not results:
del item
removeDuplicate()
The expected output:
[{
"objectID": 10745,
"results": [
{
"model": "AUDI - TT QUATTRO",
"price_str": "4 800 €"
}]
}
]