0

I have some 100 json files in one folder.

I want to construct a dataset in R that contains a column which contains complete data from each of the json file.

Dataset must contain a column say jsonfile and each row in this column should contain data from one json file i.e data from 1st json file from the folder should be in first row of this column, 2nd json file data should be in second row of the column and so on. without destroying the structure of json file in this column

Can we achieve this using R? If yes, how can we do this?

I would really appreciate any help.

2 Answers 2

1

In case your files are in a data folder you can iterate over it and add the info in a data frame

df  <- NULL
dir <- "data/"
for (file_ in list.files(dir)){
  fullPath <- paste0(dir,file_)
  content  <- readChar(fullPath, file.info(fullPath)$size)
  df       <- rbind(df, data.frame(fileName = fullPath, content = content))
}

Result: enter image description here

Sign up to request clarification or add additional context in comments.

Comments

0

Without sample data and example output it's hard to know what you're asking, but to generally to bind identical json files into a single data.frame

purrr::map_dfr(
  list.files("data/", full.names = TRUE), jsonlite::fromJSON
)

fromJSON creates a data.frame from the file. map_dfr iterates over the files and binds the data.frames together.

Comments

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.