I am looking to create a valid JSON string, with input from an R list. Each key and value needs to be quotation escaped (see expected valid JSON). I use jsonlite package for transform to JSON.
The result string is used for an API that requires the quotation escapes.
R-list:
myProducts <- list(
productOne = "x",
productTwo = "y"
)
Convert list to json format:
myJSON <- toJSON(myProducts)
Output:
{"productOne":["x"],"productTwo":["y"]}
Expected valid json / Neeed string:
"{\"productOne\": \"x\", \"productTwo\": \"y\"}"