Separate nested JSON object into separate rows and columns

Viewed 39

Need assistance parsing nested JSON object using R studio. I have a csv file with 16 columns- providing a sample here of the file with some of these columns. The main column of interest is called 'widgets' that contains a nested JSON object in below format:

enter image description here (raw data)

I need 'widgets' column to be split into 8 columns Type, Bid, Cid, x1, x2, x3, x4, x5, and 2 rows, for 'A' and 'B' Type. Would greatly appreciate the help.

enter image description here

(required output format)

I tried creating a function like below, which can parse the JSON object, but it does not solve for splitting into rows at the same time:

ParseJSONColumn <- function(x)  {
str_c("[ ", str_c(x, collapse = ",", sep=" "), " ]")  %>% 
    fromJSON(x,flatten = T) %>% 
    as.tibble()
}

JSONcolumn_data <- dwell_sample  %>% 
  select(widgets)  %>% 
  map_dfc(.f = ParseJSONColumn)
0 Answers
Related