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



When I tried to run this exact same code it gave me an error message and I could not fix it, so I allowed it to substitute in the code they offered from “replace with solution” option and even that code returned the same error message. I did not know what to do but the task box was then checked off so I moved on.

If you scroll up to see what @8-bit-gaming wrote about types of data, one is a string and one is a list type of data. the r_json object is a list, the r_text is string

The list obj. is the type of data you’d want to work with here.