-2

I have a data frame which has one column of text with info that I need to extract, here is one observation from that column: each question has three attributes associated to it objectives,KeyResults and responsible

[{"text":"Newideas.","translationKey":"new.question-4","id":4,"objectives":"Great","KeyResults":"Awesome","responsible":"myself"},{"text":"customer focus.","translationKey":"new.question-5","id":5,"objectives":"Goalset","KeyResults":"Amazing","responsible":"myself"}

-------------------------DESIRED OUTPUT -----------------------

Question#   Objectives KeyResults responsible Question#   Objectives KeyResults responsible 
4            Great      Awesome    myself       5           Goalset    Amazin     myself
Sathish
  • 12,453
  • 3
  • 41
  • 59
  • 2
    Please use `dput` to shhow the example – akrun Apr 01 '20 at 21:17
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Apr 01 '20 at 21:17

1 Answers1

2

Data is a valid json (but you need square bracket closing ] on it). You can read json into R object using json parser package (eg. jsonlite)

Let say your text is in column text of data frame df, then this will transform that text into R dataframe.

library(jsonlite)

dat <- fromJSON(df$text)
dat

#              text translationKey id objectives KeyResults responsible
# 1       Newideas. new.question-4  4      Great    Awesome      myself
# 2 customer focus. new.question-5  5    Goalset    Amazing      myself

You need to install jsonlite to make it works

install.packages("jsonlite")
nurandi
  • 1,588
  • 1
  • 11
  • 20