Skip to content

Commit

Permalink
deserialize_json_col: apply also to JSON blobs within JSON data
Browse files Browse the repository at this point in the history
  • Loading branch information
deeenes committed Jan 31, 2025
1 parent 3c0bba6 commit 53b03dd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions R/extra_attrs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 53b03dd

Please sign in to comment.