Search code examples
rjson

How to get public github JSON into R as a list of lists?


I would like to experiment with some soccer data made publicly available by Statsbomb on their github page. Here's a list to one of the JSONs from their github page that is available:

https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/7298.json

My question is, how can I get this into R? I have tried the following:

httr::content(httr::GET("https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/7298.json"))

however, this simply returns a length-1 character vector with the whole JSON squeezed into the string. I would preferably like this as a list of lists. How could I do this?

Thanks !!

EDIT: here is Statsbomb's public github repo - if it helps at all!


Solution

  • If you want to turn the JSON file in to an R object, you'll need to actually parse the data, not just download the file. the jsonlite library makes this easy

    url <- "https://raw.githubusercontent.com/statsbomb/open-data/master/data/events/7298.json"
    mydata <- jsonlite::read_json(url)
    

    And then mydata is now a big list with all the parsed values from the JSON object.