R/jq_run.R

#' Apply a jq filter to an json input
#' @export
jrun <- function(filter, input = jq_input(filter), args = c("--compact-output", "--monochrome-output"), ...) {
  if(is.character(input)) {
    if(file.exists(input)){
      file <- input
      json <- NULL
    } else {
      file <- NULL
      json <- input
    }
  } else {
    json <- toJSON(input, ...)
    file <- NULL
  }
  filter <- paste(filter, collapse = " | ")
  args <- c(shQuote(filter), args)
  if(is.null(file))
    paste(system2("jq", args = args, stdout = T, input = json), collapse = "")
  else
    paste(system2("jq", args = args, stdout = T, stdin = file), collapse = "")
}
jullybobble/jqr documentation built on May 20, 2019, 4:23 a.m.