I have a JSON file that looks like the following (not the whole file)
"route-information" : [
{
"attributes" : {"xmlns" : "http://xml.juniper.net"},
"route-table" : [
{
"comment" : "keepalive",
"table-name" : [
{
"data" : "inet"
}
],
"destination-count" : [
{
"data" : "24324"
}
],
"total-route-count" : [
{
"data" : "47432"
}
],
"active-route-count" : [
{
"data" : "43252"
}
],
"holddown-route-count" : [
{
"data" : "0"
}
],
"hidden-route-count" : [
{
"data" : "1"
}
],
I am trying to access the 'comment' part by using python. So far I have this:
import json
# read file
with open('route-table.json') as file:
data = json.load(file)
print(data["route-information"]["route-table"]["comment"])
Whenever I run this part I get the following error and I can't seem to fix it.
Traceback (most recent call last):
File "json_test.py", line 7, in <module>
print(data["route-information"]["route-table"]["comment"])
TypeError: list indices must be integers or slices, not str