I first pulled apart the xlsx file, which consisted of multiple sheets.
# install.packages("readxl")
library(readxl)
library("rjson")
# read_excel reads
df1 <- read_excel("C:/Users/Adminstrator/Downloads/file.xlsx", sheet = 1)
df2 <- read_excel("C:/Users/Adminstrator/Downloads/file.xlsx", sheet = 2)
df3 <- read_excel("C:/Users/Adminstrator/Downloads/file.xlsx", sheet = 3)
The contents of df are as follows.
Alabama Hoover 33.40556 -86.81111
Alabama Hoover 33.40565 -86.81314
Alabama Hoover 33.40555 -86.81343
Alabama Dothan 31.22722 -85.40722
Alabama Gadsden 34.01028 -86.01028
Alaska Chugiak 61.38778 -149.48139
...
I want to replace this xlsx file with json.
{
"Alabama" : {
"Hoover": {
"x":[33.40556, 33.40565, 33.40555],
"y":[-86.81111, -86.81314, -86.81343]
},
"Dothan": {
"x":[31.22722],
"y":[-85.40722]
},
...
},
"Alaska" : {
"Chugiak" : {
"x":[61.38778],
"y":[-149.48139]
},
...
}
...
}
How can I change the xlsx file to json? Please help me. thanks.