Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Unable to turn JSON to Dictionary in python from get request

I am trying to turn json I got from a GET request using an API into a dictionary that I can use. Here is what I did:

response = requests.get(API)
response_dict = json.loads(response.json())
print(response_dict)

I get the error:

raise TypeError(f'the JSON object must be str, bytes or bytearray, '
TypeError: the JSON object must be str, bytes or bytearray, not dict

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Carefully read the error. It suggests that response.json() already returns a dict. There is no need to call json.loads (which accepts a string) on it.

response = requests.get(API)
response_dict = response.json()

is all you need.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading