output_goal <- '{ "firstName": "Tim", "lastName": "Jones", "team": { "value":104290, "teamMarket": "Card", "gender": "MALE" }}'
zed1 <- list(firstName = 'Tim', lastName = 'Jones', team = list(value = 104290, teamMarket = 'Card', gender = 'MALE'))
output <- jsonlite::toJSON(zed1)
output <- gsub('\\[', '', output)
output <- gsub('\\]', '', output)
output == output_goal
> FALSE
zed2 <- list(firstName = 'Tim', lastName = 'Jones', team = data.frame(value = 104290, teamMarket = 'Card', gender = 'MALE'))
output <- jsonlite::toJSON(zed2)
output <- gsub('\\[', '', output)
output <- gsub('\\]', '', output)
output == output_goal
> FALSE
Our goal is to convert either of zed1
, zed2
into the string output_goal
. So far, we have tried to use jsonlite::toJSON
, and then gsub to remove the brackets. I believe that we are struggling with escape characters, but am not sure what else to try to get these strings to match.