The json you provide as an example indeed has only two objects in an array. The structure is faithfully shown by a called to str
:
> str(json_data,max.level=2)
List of 2
$ :List of 3
..$ projects :List of 1
..$ total_hits: num 12596
..$ seed : chr "776766"
$ :List of 3
..$ projects :List of 16
..$ total_hits: num 12596
..$ seed : chr "776766"
Guessing that you mean project id, and that you don't mind to loose the "total_hits" and
you simply need to unlist the first two levels of the json:
unlisted <- unlist(unlist(json_data,recursive=FALSE),recursive=FALSE)
And then select the items named projects*:
projects <- unlisted[grep("^projects*",names(unlisted))]
You can then simply unlist using:
data <- lapply(projects,unlist)
Rbinding is more tricky as you do not have exactly the same fields filled in all projects, you need to rely on the names, the following is one of the many solutions, and probably not the optimal one:
# list all the names in all projects
allNames <- unique(unlist(lapply(data,names)))
# have a model row
modelRow <- rep(NA,length(allNames))
names(modelRow)<-allNames
# the function to change your list into a row following modelRow structure
rowSettingFn <- function(project){
row <- modelRow
for(iItem in 1:length(project)){
row[names(project)[iItem]] <- project[[iItem]]
}
return(row)
}
# change your data into a matrix
dataMat <- sapply(data,rowSettingFn)