I'm trying to get my super-simple data frame into something a little more useful - a json array in this case. My data looks like
| V1 | V2 | V3 | V4 | V5 | |-----------|-----------|-----------|-----------|-----------| | 717374788 | 694405490 | 606978836 | 578345907 | 555450273 | | 429700970 | 420694891 | 420694211 | 420792447 | 420670045 |
and I want it to look like
[
{
"V1": {
"id": 717374788
},
"results": [
{
"id": 694405490
},
{
"id": 606978836
},
{
"id": 578345907
},
{
"id": 555450273
}
]
},
{
"V1": {
"id": 429700970
},
"results": [
{
"id": 420694891
},
{
"id": 420694211
},
{
"id": 420792447
},
{
"id": 420670045
}
]
}
]
Any thoughts on how I can make that happen? Thanks for your help!
Your
data.frame
cannot be directly written into that format. In order to get the desired json, firstly you need to turn yourdata.frame
into this structure:Here's a way to apply the transformation to your example data: