Reputation: 1276
I have a data frame in R with two columns, for example:
df = data.frame(x=c(1, 2, 3, 4), y=c(5, 6, 7, 8))
I need to write an R script to convert this data.frame to a JSON array of arrays, like this:
[[1, 5],[2, 6],[3, 7],[4, 8]]
How do I convert my data frame to a JSON array of rows in R?
Upvotes: 3
Views: 465
Reputation: 887173
We can use toJSON
from library(jsonlite)
library(jsonlite)
toJSON(setNames(df, NULL))
#[[1,5],[2,6],[3,7],[4,8]]
Upvotes: 5