Siddharth Hemrajani Siddharth Hemrajani - 1 year ago 94
JSON Question

Access JSON data in Python

header = {'Content-type': 'application/json','Authorization': 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx' }
url = ''
response =, headers = header, verify=False).json()
token = json.dumps(response)
print token['ValidThrough']

I want to print the ValidThrough Attribute in my webhook, which is received as JSON data via a POST call. I know this has been asked a number of times here, but print token['ValidThrough']isnt working for me.I receive the error "TypeError: string indices must be integers, not str"

Answer Source

Since the response already seems to be in json, there is no need to use json.dumps.

json.dumps on a dictionary will return a string which cannot be indexed obviously and hence that error.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download