I have a list my_list <- list(name="Fred", age="5")
I expected my_list %>% toJSON
to return {"name": "Fred", "age": "5"}
Instead, it returns {"name":["Fred"],"age":["5"]}
How can I convert this list to JSON whilst avoiding the square brackets?
We can use the auto_unbox
which is by default FALSE
library(dplyr)
library(jsonlite)
my_list %>%
toJSON(auto_unbox = TRUE)
#{"name":"Fred","age":"5"}
Use auto_unbox
(the default is FALSE
)
toJSON(my_list, auto_unbox =T)