I have a this json file:
{
"DailyForecasts": [
{
"Temperature": {
"Minimum": {
"Value": 2.9
},
"Maximum": {
"Value": 16.1
}
},
"HoursOfSun": 12,
"AirAndPollen": [
{
"Name": "AirQuality",
"Value": 37,
"CategoryValue": 1
},
{
"Name": "UVIndex",
"Value": 5,
"CategoryValue": 2
}
]
}
]
}
I would like to remove "CategoryValue" key from "AirAndPollen" array. I tried this Python code, but getting:
TypeError: list indices must be integers or slices, not str
My Python code:
import json
with open('accu-test.json') as f:
data = json.load(f)
for remove in data['DailyForecasts']:
del remove['AirAndPollen']['CategoryValue']
print(json.dumps(data, indent=2))
What's the recommended approach in this case? Thank you.