R/read_json_lines.R

Defines functions read_json_lines

Documented in read_json_lines

#' Read a JSON logfile
#'
#' @param file `character` scalar. path to a JSON logfile (one JSON object per line)
#' @param ... passed on to [jsonlite::stream_in()]
#' @return a `data.frame`
#' @seealso [LayoutJson]
#' @export
#'
read_json_lines <- function(file, ...){
  assert_namespace("data.table", "jsonlite")
  con <- file(file, open = "r")
  on.exit(close(con))
  res <- jsonlite::stream_in(con, verbose = FALSE, ...)

  if ("timestamp" %in% names(res)){
    res$timestamp <- as.POSIXct(res$timestamp)
  }

  res
}
s-fleck/memlog documentation built on March 6, 2023, 6:52 p.m.