0

json file

[{"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'])

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Sorry, didn't see the ':' after 'Page', see edited answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.