I have a folder with 30,000 plus JSON file. A sample file with contents is posted below.
{
"name": null, "release_date_local": null, "title": "3 (2011)",
"opening_weekend_take": 1234, "year": 2011,
"release_date_wide": "2011-09-16", "gross": 59954
}
However, I need the data in a df in a structure as given below:
name relase_date_local title opening_weekend_take year release_date gross
NA NA 3 (2011) 1234 2011 2011-09-16 5994
Here is my code snippet to get all the files as a list:
path = "./Week1/jsonfiles"
temp = list.files(path, pattern = "*.json")
filename = paste(path, temp, sep = "/")
movies = c()
for (i in filename){
movie = fromJSON(file = i)
movies = c(movies, movie)
}
Please advise, how can I read all 30,000 files as rows of a df?
temp <- list.files(path, pattern = "*.json", full.names = TRUE); movies <- purrr::map_df(temp, function(x) { purrr::map(jsonlite::fromJSON(x), function(y) ifelse(is.null(y), NA, y)) })
$\endgroup$