Extract contents from json like column

Hi have a column with data in this format

"{'id': 8475778, 'body': 'Hi Ais.hes, we appreciate your feedback and we would like to interact with you to resolve any issue you may be having, kindly share with us your contact information to enable us speak with you or send a mail to user@domain.com and a customer success representative would get in touch with you.', 'modified': '2019-05-02T10:57:07Z'}"

Each value in the column looks like this, I'm not sure how to extract the values into separate columns e.g
id ------ body ------ modified

Please help. Thanks

library(tidyverse)
example_df <- tibble(
  a = "some info",
  embedded_almostjson = "{'id': 8475778, 'body': 'Hi Ais.hes, we appreciate your feedback and we would like to interact with you to resolve any issue you may be having, kindly share with us your contact information to enable us speak with you or send a mail to user@domain.com and a customer success representative would get in touch with you.', 'modified': '2019-05-02T10:57:07Z'}"
)


(ex2 <- mutate(example_df,
  json = str_replace_all(embedded_almostjson, "'", '"')
))

library(jsonlite)

(ex3 <- bind_cols(ex2, map_dfr(ex2$json, fromJSON)) %>% select(
  -embedded_almostjson,
  -json
))
1 Like