Reputation: 857
I want to return an output similar to the below in R
"outputFiles": [
{
"dealType" : "Scanback",
"claimNumer" : "1234",
"dealDescription" : "deal1",
"requestOutputFileName" : "<filename>",
"filePath" : "c:/processed/files/<FileName>"
},
{
"dealType" : "Rebate",
"claimNumer" : "1234",
"dealDescription" : "deal2",
"requestOutputFileName" : "<filename>",
"filePath" : "c:/processed/files/<FileName>"
}
]
I have "dealType" , "claimNumber", "dealDescription", "requestOutputFileName" and "filePath" as vectors.
e.g.,
> dealType
[1] "scanback" "rebate"
I am not able to get it in the above structure.
How can this be achieved using R?
Upvotes: 0
Views: 27
Reputation: 1423
Doesn't toJSON()
from jsonlite
simply work, if you combine your vectors into a dataframe ?
toJSON(data.frame(dealtype, ClaimNumer...),
pretty = TRUE)
Upvotes: 1
Reputation: 389205
Would it work if you put the vectors in a dataframe and then use toJSON
to get it in JSON format.
dealType <- c("scanback", "rebate")
claimNumer <- c(1234, 1234)
df <- data.frame(dealType, claimNumer)
jsonlite::toJSON(df)
#[{"dealType":"scanback","claimNumer":1234},{"dealType":"rebate","claimNumer":1234}]
Upvotes: 1