0

Here is the JSON data in question:

{
  "result_index": 0,
  "results": [
    {
      "alternatives": [
        {
          "confidence": 0.994,
          "transcript": "thunderstorms could produce large hail isolated tornadoes and heavy rain "
        }
      ],
      "final": true
    }
  ]

}

Here is how I am attemption to access it.

parsed = json.loads(data)
print(parsed['results']['alternatives']['transcript'])

This results in the following error:

TypeError: list indices must be integers or slices, not str

It seems as though results is just an array with a single entry that is a string, and I am a bit confused how to access the individual elements within it.

2
  • results and alternatives are arrays so maybe parsed['results'][0]['alternatives'][0]['transcript'] Commented Sep 8, 2016 at 19:38
  • That was it, thanks so much! Commented Sep 8, 2016 at 19:40

1 Answer 1

1

Your results and alternatives are not objects; but arrays of objects.

print(parsed['results'][0]['alternatives'][0]['transcript'])
Sign up to request clarification or add additional context in comments.

1 Comment

Yup, that did it, thanks for the explanation as well.

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.