| 1 |
#' Read a JSON logfile |
| 2 |
#' |
| 3 |
#' @param file `character` scalar. path to a JSON logfile (one JSON object per line) |
| 4 |
#' @param ... passed on to [jsonlite::stream_in()] |
| 5 |
#' @return a `data.frame` |
| 6 |
#' @seealso [LayoutJson] |
| 7 |
#' @export |
| 8 |
#' |
| 9 |
read_json_lines <- function(file, ...){ |
| 10 |
assert_namespace("data.table", "jsonlite") |
| 11 |
con <- file(file, open = "r") |
| 12 |
on.exit(close(con)) |
| 13 |
res <- jsonlite::stream_in(con, verbose = FALSE, ...) |
| 14 |
|
| 15 |
if ("timestamp" %in% names(res)){ |
| 16 |
res$timestamp <- as.POSIXct(res$timestamp) |
| 17 |
} |
| 18 |
|
| 19 |
res |
| 20 |
} |