Reading list of json files using for loop

Hi all,

I am trying to read list of json files in my local folder. But the below code does not work. Can anyone help me in solving this

json_files <- list.files(pattern = "*.json")
for(i in length(json_files))
{
json_data3[[i]] <- fromJSON(paste(readLines[[i]],collapse = ""))
}

What is this element readLines ? Is this the function readLines ?
I think the file path is in json_files[[i]] isn't it ?
Why do you try to use paste ?

jsonlite::fromJSON can read from a file. see ?jsonlite::fromJSON

You could manage to do it maybe with

json_data <- purrr::map(json_files, fromJSON)

See purrr for functional programming helpers.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.