Siddharth Hemrajani Siddharth Hemrajani - 8 months ago 38
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"


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.