我正在尝试从数据框创建嵌套的JSON文件。有人可以帮我解决这个问题吗?
sample <- data.frame(id=c(1,2,3,4,5),names = c('a','b','c','d','e'),
type = c('xx','xx','yy','xx','zz'),
height = c(12,10,11,13,15),
width = c(2,3,5,4,4))
jsonlite::toJSON(sample, pretty=TRUE, auto_unbox=TRUE)
给我这个结果,
[
{
"id": 1,
"names": "a",
"type": "xx",
"height": 12,
"width": 2
},
{...
},
{...
},
...
]
我希望结果像这样嵌套,
[
{
"id": 1,
"names": "a",
"metadata": {
"type": "xx",
"height": 12,
"width": 2
}
},
{...
},
{...
},
...
]
如何获取这种格式的数据?任何帮助,将不胜感激。 谢谢!