Search code examples
rjsonfunctionurlget

R GET JSON from list of urls and assign names


I am trying to create a function to GET JSON data from a list of URLs and assign names accordingly.

I have dataset for many metrics. The head looks like:

I can extract one by one with:

Local <- GET("https://www.ons.gov.uk/economy/grossdomesticproductgdp/timeseries/abmi/pn2/data") %>%
  content(as = "text") %>%  
  fromJSON() 

But I cannot figure out how to create a function that can be applied to the datasets, and that get the JSON and assign the name accordingly without having to run one by one for each row. Thank you.


Solution

  • lapply(dataset$Url, function(i) fromJSON(content(GET(i), as = 'text'))) @Allan Cameron Thank you