I have a json output from http request like this:
print(resp)
{'totalCount': 1, 'pageSize': 50, 'entities': [{'entityId': 'HOST-12345', 'displayName': 'beff'}]}
{'totalCount': 1, 'pageSize': 50, 'entities': [{'entityId': 'HOST-7898', 'displayName': 'dude101'}]}
{'totalCount': 1, 'pageSize': 50, 'entities': [{'entityId': 'HOST-56890', 'displayName': 'prop'}]}
I need to grab the entityId from this list:
HOST-12345
HOST-7898
HOST-56890
I have this:
print(resp['entities']['entityId'])
I get this error:
TypeError: list indices must be integers or slices, not str
resp['entities'][0]['entityId']resp['entities']is a list with a single element... You need to first take that single element by indexing the list with[0]and then you get the dict to access with['entityId']