I'd like to change the delivery window value. Here is the original data structure.
{
"locations":[
{
"depot_duration_s":90,
"depot_id":"depot_1",
"time_window":"09:00-20:00",
"type":"delivery"
},
{
"depot_duration_s":90,
"depot_id":"depot_1",
"time_window":"09:00-20:00",
"type":"delivery"
},
{
"depot_duration_s":90,
"depot_id":"depot_1",
"time_window":"09:00-20:00",
"type":"delivery"
}
]
}
Here is the code I tried, but I got "list indices must be integers or slices, not str". Could you let me know how to fix the code here?
import json
with open('C:/Users/8_31_file.json', 'r+', errors = "ignore") as myData:
myData = json.load(myData)
mylist = myData["locations"][-2:]
mylist["time_window"] = "17:00-20:00"
mylist = {'locations':mylist}
print(mylist)