I'm getting data from an API which returns a JSON list with sub-lists of varying lengths. I would like to flatten the structure into a data frame in R. Below is the code I've used thus far however, each of my 'rows' or lists contain a varying number of objects (columns). What is the best way to do this in R? I'm assuming it may be some modification of the sapply function??
library(httr)
library(jsonlite)
rf <- GET("https://data.fortworthtexas.gov/resource/2ys6-nns2.json?fatality=True")
rfc <- content(rf)
rff <- fromJSON(rfc, simplifyDataFrame = TRUE)
json_file <- sapply(rfc, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
json_file$id <- rownames(json_file)