I have a log file that look like this.
I'm trying to parse the JSON in the Message
column by:
library(readr)
library(jsonlite)
df <- read_csv("log_file_from_above.csv")
fromJSON(as.character(df$Message))
But, I'm hitting the following error:
Error: parse error: trailing garbage
"isEmailConfirmed": false } { "id": -1, "firstName":
(right here) ------^
How can I get rid of the "trailing garbage"?
fromJSON()
isn't "apply"ing against the character vector, it's trying to convert it all to a data frame. You can trywhat @Abdou provided or
The latter two will create data frames. The first will create a list you can add as a column.
You can use the last method with
dplyr::bind_cols
to make a new data frame with all the data:Also suggested by @Abdou is an almost pure base R solution:
Full, working, workflow: