Nov-17-2020, 01:29 AM
If we look at your JSON with the structures formatted:
{ "text_to_speech": [ { "api_key": "xxxxxxxxxxxxxxxxxx", "api_url": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ], "speech_to_text": [ { "api_key": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "api_url": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" } ] }You can more easily see that the api_key element isn't directly inside the "text_to_speech" dictionary, it's inside a list within. So you'd need to either get rid of that enclosing list, or you'd have to access it by asking for the first element in that list:
>>> data["text_to_speech"]["api_key"] Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: list indices must be integers or slices, not str >>> data["text_to_speech"][0]["api_key"] 'xxxxxxxxxxxxxxxxxx'