I need to pass JSON object to a function in r programming. The following are the various examples of JavaScript objects that can be passed which needed to be converted to JSON in r
Example1 = [
{name: "Orange", data: {"Tuesday": 3, "Friday": 4}, stack: "fruit"},
{name: "Apple", data: {"Tuesday": 1, "Friday": 8}, stack: "fruit"},
{name: "Cucumber", data: {"Tuesday": 3, "Friday": 4}, stack: "vegetable"},
{name: "Carrot", data: {"Tuesday": 1, "Friday": 8}, stack: "vegetable"}
]
Example2 = [["Washington", "1789-04-29", "1797-03-03"], ["Adams", "1797-03-03", "1801-03-03"]]
I need help converting them into a JSON object in r using jsonlite package.
2
Answers
Thank you @margusl I just resolved Example1
But, this is not actually what I want. I wish I could achieve the same output as what I would get in JavaScript when I use JSON.stringify() where the keys are quoted. I hope I could get help here
Javascript code can be evaluated with
v8
, that code can includeJSON.stringify()
, but for a list of simple assignment expressions we can setserialize
parameter for$eval()
method and it will return JSON string:Created on 2023-07-23 with reprex v2.0.2