Reputation: 3
[{"Attachment": [
{
"Page:": [
{
"Path": "a\\b\\c.pdf", #field to be extracted
"PageID": 1
}
]
}
],
"ID": 13221}]
I tried the following but getting the TypeError: list indices must be integers, not str
with open(file) as f:
d = json.load(f)
print(d[0]['Attachment']['Page']['Path'])
Upvotes: 0
Views: 338
Reputation: 277
d[0]['Attachment']
is a list, so is d[0]['Attachment'][0]['Page:']
.
with open(file) as f:
d = json.load(f)
print(d[0]['Attachment'][0]['Page:'][0]['Path'])
will do the job.
Upvotes: 2