diff --git a/R/json.R b/R/json.R index bc47de2..6e2296a 100644 --- a/R/json.R +++ b/R/json.R @@ -277,6 +277,14 @@ setMethod("toJSON", "list", paste(sprintf("[%s", collapse), paste(els, collapse = sprintf(",%s", collapse)), sprintf("%s]", collapse)) }) +setMethod("toJSON", "data.frame", + function(x, container = isContainer(x, asIs, .level), collapse = "\n", ..., .level = 1L, .withNames = length(x) > 0 && length(names(x)) > 0, .na = "null", .escapeEscapes = TRUE, pretty = FALSE, asIs = NA) { + # Data frame columns should always be treated as containers + toJSON(lapply(as.list(x), function(col) { + I(col) + }), container = container, collapse = collapse, ..., .level = .level, .withNames = .withNames, .na = .na, .escapeEscapes = .escapeEscapes, pretty = pretty, asIs = asIs) + }) + jsonPretty = function(txt) diff --git a/man/toJSON.Rd b/man/toJSON.Rd index 1aee176..d8ef501 100644 --- a/man/toJSON.Rd +++ b/man/toJSON.Rd @@ -2,6 +2,8 @@ \alias{toJSON} \alias{toJSON,list-method} \alias{toJSON,ANY-method} +\alias{toJSON,array-method} +\alias{toJSON,function-method} \alias{toJSON,numeric-method} \alias{toJSON,integer-method} \alias{toJSON,integer,missing-method} @@ -11,7 +13,7 @@ \alias{toJSON,matrix-method} \alias{toJSON,ANY-method} \alias{toJSON,name-method} -\alias{toJSON,list-method} +\alias{toJSON,data.frame-method} \alias{toJSON,NULL-method} \alias{toJSON,factor-method} \alias{toJSON,AsIs-method}