I'm trying to get data from the World Bank (https://datahelpdesk.worldbank.org/knowledgebase/articles/898581-basic-api-call-structures). Specifically, I'm trying to query the API, parse the JSON output into R and return a data frame, where each row is a country.
I went to the website and obtained the JSON output URL (for url) below. My code is the following:
library('tidyverse')
library('httr')
library('jsonlite')
url <- 'http://api.worldbank.org/v2/country/all/indicator/SP.POP.TOTL?format=json'
r <- GET(url, query = list(q = "country"))
json <- content(r, "parsed")
json_as_text <- content(r, "text")
json <- fromJSON(json_as_text)
df <- json$country %>% as_tibble()
However, the data frame returned is empty. I'm new to APIs, and essentially trying to return a list of countries available on the website. Any ideas how to do this?