I'm trying to use map function to create json from nested list. The inner most list is not being accessed each element instead a whole list. Also lot of other issues. Please advise other ways as well.
r
g1
$EADS03
[1] "AGG101" "AGG102"
$EADS14
[1] "AT01S" "AT02S" "LM09S" "PB20S" "S206S"
$EADS142
[1] "AT01S" "AT02S" "LM09S" "PB20S"
m1 <- map(names(g1) ,~list(models = list(name= .x, version = list(major = 6, minor = 4, attributes = map(g1[.x], ~list(name = .x)))))
+ )
toJSON(m1, pretty=TRUE, auto_unbox = TRUE)
Result :
[
{
"models": {
"name": "EADS03",
"version": {
"major": 6,
"minor": 4,
"attributes": {
"EADS03": {
"name": ["AGG101", "AGG102"]
}
}
}
}
},
.....
Expected Result:
{
"models": [
{
"name": "EADS03",
"version": {
"major": 6,
"minor": 4
},
"attributes": [
{
"name": "AGG101",
"type": "number"
},
{
"name": "AGG102",
"type": "number"
}
]
},
{
"name": "EADS14",
"version": {
"major": 6,
"minor": 4
},
"attributes": [
{
"name": "AT01S",
"type": "number"
},
{
"name": "AT02S",
"type": "number"
},
{
.....
}
]
},
{
....
}
]
}
``