I am converting from python to R and this is my first attempt at Parsing Json. I have tried jsonlite, RJSONIO, and rjson. All of them stop at the getlabskaters <- fromJSON(getlabskatersRaw). To explain this script a little bit, because I clearly need some help on how to properly parse json It starts buy going to one website that returns some teams that I than use in the for loop to return all the players with that list of teams. Whats weird is the error does not occur when I run the above fromJSON it only happens when I put it into the for loop. I have checked the paste0 and the links by print(getlabskatersRaw). All of them appear fine to browse to. Some help with the error would be awesome and if your bored and have any advice on better parsing tactics I am all ears.
library(magrittr)
library(readr)
library(tidyr)
library(dplyr)
library(lubridate)
library(jsonlite)
library(httr)
library(stringi)
library(tidyverse)
library(httr)
# GET Todays date
today <- Sys.Date()
#Json return from URL
getlabteamsRaw<-paste0('https://www.fantasylabs.com/api/lines/4/', as.character(today),'/startinggoalies')
# Turn Value into List
getlabteams <- fromJSON(getlabteamsRaw)
# Parse home team
team<-getlabteams$GoalieMatchups$Properties$HomeTeam
# Convert
Home_Fullname<-as.data.frame(team)
team<-getlabteams$GoalieMatchups$Properties$VisitorTeam
Away_Fullname<-as.data.frame(team)
LabTeams <- full_join(Home_Fullname, Away_Fullname, by = c("team"))
# PLAYER INDIVIDUAL NULL DF's
lab_skaters_df <- NULL
for(labtm in LabTeams){
getlabskatersRaw<-paste0('https://www.fantasylabs.com/api/lines/4/', as.character(labtm),'/', as.character(today))
### THE ERROR IS HERE########
getlabskaters <- fromJSON(getlabskatersRaw)
# Parse Player name
new<-getlabskaters$PlayerLines$Properties$FullName
# Convert Value to Dataframe
Fullname<-as.data.frame(new)
#APPEND FEATURE
lab_skaters_df <- rbind(lab_skaters_df, Fullname)
}
I recognize this is a non-answer as I'm just dumping in code, and not explaining the issue, but this will work for you. I also cleaned up your code (you're notably loading up a bunch of packages you're not actually using, or are already loaded via
library(tidyverse)), and I'm using themap_dffunction from thepurrrpackage to loop through the teams instead of a for loop.