R/asJSON.difftime.R

setMethod("asJSON", "ts", function(x, ...) {
  asJSON(as.vector(x), ...)
})

setMethod("asJSON", "hms", function(x, hms = c("string", "secs"), ...) {
  hms <- match.arg(hms)
  output <- switch(hms,
                   string = as.character(x),
                   secs = as.numeric(x, units = "secs")
  )
  output[is.na(x)] <- NA
  asJSON(output, ...)
})

Try the jsonlite package in your browser

Any scripts or data that you put into this service are public.

jsonlite documentation built on July 9, 2023, 6:11 p.m.