user1790894
user1790894

Reputation: 417

Create Array of JsonObject in R

I am able to create a json object from list in R using rJson .

I used

config <- list([Portname="PORT.H.2",MktValue="8000000",WtScheme="Closed"])
json <- toJSON(config) 

How can I pass array of keyvalue pair to my R function and then convert it to jsonArray in R

I would like to pass

  {[Portname="PORT.H.1",MktValue="1000000",WtScheme="Variable], [Portname="PORT.H.2",MktValue="8000000",WtScheme="Closed"]}

Upvotes: 2

Views: 529

Answers (1)

user1609452
user1609452

Reputation: 4444

require(rjson)
config <- list(Portname="PORT.H.1",MktValue="1000000",WtScheme="Variable")
config2 <- list(Portname="PORT.H.2",MktValue="8000000",WtScheme="Closed")
json <- toJSON(list(config,config2)) 
cat(json)
#[{"Portname":"PORT.H.1","MktValue":"1000000","WtScheme":"Variable"},{"Portname":"PORT.H.2","MktValue":"8000000","WtScheme":"Closed"}]> 

Upvotes: 2

Related Questions