Open sjackman opened 9 years ago
@BernhardKonrad I tried to use jsonlite::fromJSON
with gameday
.
Yes, jsonp is not json. You should only use jsonp to avoid cross domain problems in the browser. Just use regular json in R.
The API that I'm using (see the example above) unfortunately does not provide JSON, only JSONP. It would be a nice-to-have feature if parseJSON
detected and removed the JSONP padding.
Try something like this:
library(httr)
req <- GET("http://live.nhle.com/GameData/GCScoreboard/2014-11-10.jsonp")
jsonp <- content(req, "text")
json <- gsub('([a-zA-Z_0-9\\.]*\\()|(\\);?$)', "", jsonp, perl = TRUE)
data <- fromJSON(json)
Regex from here.
Thanks for the workaround. Would you consider adding a fromJSONP
function? It would be a nice convenience.
I'll think about it, but it's a bit silly really. jsonp is just a hack for json to bypass the cross origin policy. It makes no sense outside of the browser. I can't think of why any API would provide jsonp but not json.
Me neither. I agree it's dumb, but that's what I'm working with.