1

I am trying to pass a variable in the url and flatten using jsonlite, but i am not able to pass variable pages using the loop. How do i loop using FromJSON?

pages<- list()
for(i in 1:20) {
mydata <- fromJSON("https:www.example.com/page="+i+"&access_token=xyz", flatten = TRUE) 
}
filings <-rbind.pages(pages)

1 Answer 1

1

What about this?

pages<- list()
for(i in 1:20) {
  mydata <- fromJSON(paste("https:www.example.com/page=", i, "&access_token=xyz", sep = "+"), flatten = TRUE)
}
filings <-rbind.pages(pages)
Sign up to request clarification or add additional context in comments.

5 Comments

you are missing the flatten=TRUE which is quite important for the nested json objects.
Answer modified, copy it simply to the end of fromJSON function.
it is only giving 1 page information after i do the rbind.
The for loop work correctly. The mistake is in the last line of your code. Try something like rbind(mydata) or provide reproducible data.
yes it was able to retrieve the pages but it is not rbinding them.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.