Home > Software engineering >  Save.json file locally in R
Save.json file locally in R

Time:04-25

I'm generating a .json file from a data.frame, but I would like to save this generated .json file on my computer, that is, locally. How to adjust this?

library(jsonlite)

df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))
df1<-toJSON(df1)

CodePudding user response:

When we use read_excel and wants to retrieve all the sheets, get the sheets first, then loop over those and specify the sheet name in sheet, and them into a list

library(readxl)
library(purrr)
sheet_nms <- excel_sheets("C:/Users/Livia/Desktop /df1.xlsx")
lst1 <- map(sheet_nms, ~ read_excel("C:/Users/Livia/Desktop /df1.xlsx", 
         sheet = .x))

Regarding the original question, we can write with write_json

library(jsonlite)
write_json(df1, "C:/Users/Livia/Desktop/df1file.json")
  • Related