R/parse_json_test.R

Defines functions parse_json_test

Documented in parse_json_test

#' Safely parse JSON to R object
#'
#' @param obj object read from JSON
#' @param parse_functions list of function names, keys are the elements in the object
parse_json_test <- function(obj, parse_functions = list()) {
  for(key in names(parse_functions)) {
    if(!is.null(obj[[key]]) && length(obj[[key]]) > 0) {
      suppressWarnings( {
        tmp <- list()
        tmp[[key]] <- obj[[key]]
        obj[[key]] <- do.call(parse_functions[[key]], tmp)
      })
    }
  }
  return(obj)
}
InsightRX/json2test documentation built on May 12, 2021, 9:49 p.m.