0

Is there a way to unnest wider a JSON file without having to know every aspect of the structure? I've asked and received an answer, but when trying with what I thought would be the same JSON structure I am running into issues.

My dput output is too large for here (I've tried to capture enough of the variability of the lists generated), so I've just put into a google doc that can be found here.

This seems to start the process off...

wide_df <- json_df %>% 
  map_if(is.data.frame, list) %>% 
  as.data.frame()

...but I'm stuck how to unnest tagEvents.tagResource and tagEvents.tagAttributes

seansteele
  • 619
  • 3
  • 10

1 Answers1

0

This is ugly as all get out but unnests wider and I can clean up from there.

wide_json <- json_df %>% 
  purrr::map_if(is.data.frame, list) %>% 
  as.data.frame() %>% 
  tibble::as_tibble() %>%
  tidyr::unnest(tagEvents.tagResource) %>% 
  dplyr::mutate(., x = purrr::map(tagEvents.tagAttributes, unlist)) %>%  
  tidyr::unnest_wider(x, names_repair = 'universal')
seansteele
  • 619
  • 3
  • 10