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

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.