How can I generate a `.json` file for all sheets

I have questions about how to convert an excel file with more than one sheet to .json format

I have a database in Excel, with 4 sheets, then I do the following command to read: df1<-read_excel('C:/Users/Jojo/Desktop /df1.xlsx'), but it only reads the first sheet, so when I run write_json(df1, "yourfile.json"), it doesn't generate a file. .json for all sheets, just to first. So how can I generate a .json file for all sheets together?

Looping through the sheets and concatenating the data, then writing it out to JSON would be one not so elegant but very workable solution:

library(dplyr)
df1 <- lapply(
    readxl::excel_sheets('df1.xlsx'),
    function(sheet) {
        read_excel(
            path = 'df1.xlsx',
            sheet = sheet
        )
    }
) %>%
    bind_rows(.)

write_json(df1, 'yourfile.json')
1 Like

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

If you have a query related to it or one of the replies, start a new topic and refer back with a link.