Nina
Nina

Reputation: 47

.json file is too large to be opened in R with rjson

I have a 5.1 GB json file that I would like to read in R using rjson. I want afterwards to construct a dataframe from it, however it won't load because the size is too large.

Is there any way to work around it?

Thank you for your help =)

Upvotes: 2

Views: 1055

Answers (1)

rg4s
rg4s

Reputation: 897

Nina, I would recommend you using jsonlite package instead of rjson.

library(jsonlite)
your_json <- "your_path.json"
unpacked_json <- jsonlite::stream_in(textConnection(readLines(your_json, n=100000)),verbose=F)

Here you limit the page size to let IDE correctly read your JSON file. For more information I would also recommend you to make some research on this topic:

  1. https://community.rstudio.com/t/how-to-read-large-json-file-in-r/13486
  2. Reading a huge json file in R , issues

I know for sure that it is sometimes really hard to cope with documentation (and as all other human beings we are lazy); and I don't like to read doc-n myself, but I highly recommend you to make yourself familiar with jsonlite documentation and vignettes. Here's the CRAN link: https://cran.r-project.org/web/packages/jsonlite/index.html

Upvotes: 2

Related Questions