I'm trying to parse some results from an API. The API returns a JSON result for a given value. The API can only handle one value at a time so I lapply
to get all the results. <- If this is a bad start point happy to here a better way!
Each JSON response has some nested info. I'm trying to get the data into one single data.frame with the nested structure resolved.
I've been playing around with jsonlite and purrr for much of the afternoon trying to get this working and ideally resilient.
How does one successfully convert a nested json structure into a data.frame for multiple json documents/records using R?
MRE
library(jsonlite)
a <- LETTERS[1:5]
b <- letters[1:5]
c <- rep(data.frame(d=LETTERS[1:5]),5)
strSetup <- list(a, b, c)
dfSetup <- data.frame(a, b, c)
jsonStr <- toJSON(rep(strSetup,3))
finalStr <- rbind(dfSetup,dfSetup,dfSetup)
I'm trying to go from jsonStr
to finalStr
.