I'm making a request to a REST API endpoint:
import requests
import json
response = requests.get(<URL>, headers=headers)
I get the following when doing a print json.loads(response.content)
:
{'data': [{'reference': '123', 'name': 'example', 'risk': 'LOW', 'status': 'tbd', 'Description': None, 'found': '2021-04-21', 'last_tested': None, 'resolved': '2021-04-29', 'notes': 'legacy', 'clientid': {'clientname': 'xyz'}, 'categoryid': {'category': 'test1'}, 'subcategoryid': {'SubCategory': 'test2'}}]}
Is this valid JSON? I am getting errors and it seems to stem from the "[" to the right of "data". For example, how would I access the 'reference' value, and even the 'category' (nested) value?
Example, doing this:
print (json_response["data"]["reference"])
Results in:
list indices must be integers or slices, not str