I am creating an JSON file from a list in R. The format of the list is quite nested.
"ageValues", whereby "ageValues" is repeated many time, always with a differnt name. The list in R looks like:
ageBucket <- list(startAge = 0L, endAge = 59L, price = 0, expectedInsureds = 0)
ageValue <- as.array(list(price = 0, expectedInsureds = 0))
noAgeValues <- 59
ageValues <- rep(list(ageValue), noAgeValues+1)
names(ageValues) <- c(1:60)
ageBucket <- c(ageBucket, (ageValue = list(ageValues)))
toJSON(ageBucket)
I want to create an JSOn file of this format:
...[{ "price": 0, "expectedInsureds": 0 }, ... ]...
but i am getting this instead:
...{"price":[0],"expectedInsureds":[0]},...
How can this be done, without changing the argument in toJSON(ageBucket)
i tried:
lapply(ageValues, function(x) as.array(x, letters))
but i guess i am misunderstanding something?