R & APIs 6 Converting to Dataframe - Unclear instructions

Screen Link:

My Code:

wb_api_json_get_df <- function(endpoint) {
  # Preparing the URL 
  url <- modify_url("http://api.worldbank.org", path = endpoint)
  # API requests
  response <- GET(url)

  # Tracking errors
  if ( http_error(response) ){
    stop("Something went wrong.", call. = FALSE)
  if (http_type(response) != "application/json") {
    stop("API did not return json", call. = FALSE)
  # Extracting content
  json_text <- content(response, "text")
  # TODO 1: add code to convert the extracted content into a dataframe
  df <- jsonlite::fromJSON(json_text)[[2]]
  # TODO 2: modify to return the dataframe 

# Type the answer to the second instruction below
wb_indicator_json_df <- wb_api_json_get_df("v2/indicator?format=json")

What I expected to happen:
The full response is a list, with some other information within the first element, so to get only the dataframe I subset to use only the second element (jsonlite::fromJSON(json_text)[[2]]). Also the instructions indicate that what I want as the end result is a structured dataframe.

What actually happened:
However, when I do that, I get an error complaining that my result is a dataframe, but a list is expected.
The “correct” response is the one without subsetting, thus returning a list.
Perhaps the World Bank API has changed since you wrote the course? In any case this is somewhat contradicting the instructions.

By the way, the URL to the quest I posted is correct, but it renders as a link to another page…

Okay, it’s clear in the following step that here we should get a list, so I would suggest you change the instructions (and title of) in quest 6 accordingly:

Edit the previous wb_api_json_get_df() function.

  • Use the jsonlite::fromJSON() function to convert the extracted content into a list.
  • Return this output.
  • We name this output as json_list, but feel free to name it differently.