1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
|
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/json.R
\name{tojson}
\alias{tojson}
\alias{json_vector}
\title{A simple JSON serializer}
\usage{
tojson(x)
json_vector(x, to_array = FALSE, quote = TRUE)
}
\arguments{
\item{x}{An R object.}
\item{to_array}{Whether to convert a vector to a JSON array (use \code{[]}).}
\item{quote}{Whether to double quote the elements.}
}
\value{
A character string.
}
\description{
A JSON serializer that only works on a limited types of R data (\code{NULL},
lists, logical scalars, character/numeric vectors). A character string of the
class \code{JS_EVAL} is treated as raw JavaScript, so will not be quoted. The
function \code{json_vector()} converts an atomic R vector to JSON.
}
\examples{
library(xfun)
tojson(NULL)
tojson(1:10)
tojson(TRUE)
tojson(FALSE)
cat(tojson(list(a = 1, b = list(c = 1:3, d = "abc"))))
cat(tojson(list(c("a", "b"), 1:5, TRUE)))
# the class JS_EVAL is originally from htmlwidgets::JS()
JS = function(x) structure(x, class = "JS_EVAL")
cat(tojson(list(a = 1:5, b = JS("function() {return true;}"))))
}
\seealso{
The \pkg{jsonlite} package provides a full JSON serializer.
}
|