Making API request in Python Question #4


Question #4 asks :
"Use the .json() method to access the decoded JSON data and store it in a variable called r_json. Try printing out r_json. Can you see the advantage working with r_json has over r_text?"

I don’t see any differences/advantages between the two. Can anyone explain what it is? It looks the same as one another except for having single quotes (json) vs double quotes (text). Not sure if this has any significance. Thanks!

Could you post your code for us to see? It can be a bit harder to help with out knowing for sure were you’re at :sweat_smile:
Specifically what is assigned to r_text and r_json is what I’m getting at.

Without seeing your code I do have a hunch. Have you tried printing type(r_text) and type(r_json)? Are they both the same? Or could one be easier to work with?

1 Like

Hi, sorry about that. Below is my code:

import requests

r = requests.get(‘,B08303_001E,B08303_013E&for=county:*&in=state:36’)

r_text = r.text

r_json = r.json()

1 Like

Thank you much! Yep, that’s what I thought!
Try what I recommended earlier, should see a bit of a differnce :wink:

r_text is class str
r_json is class list