"TypeError: string indices must be integers" after reading from a JSON file
On line 14, this is not valid, given the input data:
lons.append(cp_dicts['geometries']['coordinates'][0]
You need to update the loop along these lines:
for geometry in all_cp_dicts['objects']['capitals']['geometries']:
lons.append(geometry['coordinates'][0])
lats.append(geometry['coordinates'][1])
hover_texts.append(geometry['properties'].get('city', ""))
Note that for some of the locations, the 'cities' key is missing in the json. So you need to handle that when populating the hover_texts
list, as shown.
Also, the 'data' variable was not working with Scattergeo. Below is a suggested revision to the syntax
data = Scattergeo(
lat = lats,
lon = lons,
text = hover_texts,
marker = dict(
size = 5
)
)