diff --git a/R/extra_attrs.R b/R/extra_attrs.R index 714bb7d9..730c56a1 100644 --- a/R/extra_attrs.R +++ b/R/extra_attrs.R @@ -68,11 +68,32 @@ deserialize_json_col <- function(data, col, ...) { {log_trace('Converting JSON column `%s` to list.', col)} %>% mutate(!!sym(col) := map(!!sym(col), fromJSON, !!!fromjson_args)), . + )} %>% + {`if`( + !is.data.frame(data), + map(., ~exec(json_in_list, .x, key = col, !!!fromjson_args)), + . )} } +#' In each sublist, deserialize a JSON encoded value if key exists +#' +#' @importFrom jsonlite fromJSON +#' @importFrom magrittr %<>% +#' @noRd +json_in_list <- function(x, key, ...) { + + if(!is.null(x[[key]]) && is.character(x[[key]])) { + x[[key]] %<>% fromJSON(...) + } + + x + +} + + #' Extra attribute names in an interaction data frame #' #' Interaction data frames might have an `extra_attrs` column if this field