Skip to content

Instantly share code, notes, and snippets.

@statwonk
Created January 26, 2014 22:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save statwonk/8640352 to your computer and use it in GitHub Desktop.
Save statwonk/8640352 to your computer and use it in GitHub Desktop.
install.packages("RCurl"); install.pacakges("rjson")
library(RCurl); library(rjson)
df <- fromJSON(getURL("https://raw.github.com/BurntSushi/nflgame/master/nflgame/players.json"))
dataframeFromJSON <- function(l) {
l1 <- lapply(l, function(x) {
x[sapply(x, is.null)] <- NA
unlist(x)
})
keys <- unique(unlist(lapply(l1, names)))
l2 <- lapply(l1, '[', keys)
l3 <- lapply(l2, setNames, keys)
res <- data.frame(do.call(rbind, l3))
return(res)
}
df <- dataframeFromJSON(df)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment