toJSON {jsonlite} |
R Documentation |
Convert R objects to/from JSON
Description
These functions are used to convert between JSON data and R
objects. The toJSON and fromJSON functions use a class based
mapping, which follows conventions outlined in this paper:
https://arxiv.org/abs/1403.2805 (also available as vignette).
Usage
toJSON(x,
dataframe = ['columns','values'],
matrix = ['columnmajor'],
Date = ['epoch'],
POSIXt = ['ISO8601','epoch','mongo'],
factor = ['integer'],
complex = ['list'],
raw = ['hex','mongo','int','js'],
null = ['null'],
na = ['string'],
auto.unbox = FALSE,
digits = 4,
pretty = FALSE,
force = FALSE,
args = NULL);
Arguments
x
the object to be encoded
dataframe
how to encode data.frame objects: must
be one of 'rows', 'columns' or 'values'
matrix
how to encode matrices and higher dimensional
arrays: must be one of 'rowmajor' or 'columnmajor'.
Date
how to encode Date objects: must be one of
'ISO8601' or 'epoch'
POSIXt
how to encode POSIXt (datetime) objects:
must be one of 'string', 'ISO8601', 'epoch' or 'mongo'
factor
how to encode factor objects: must be one
of 'string' or 'integer'
complex
how to encode complex numbers: must be
one of 'string' or 'list'
raw
how to encode raw objects: must be one of
'base64', 'hex' or 'mongo'
null
how to encode NULL values within a list:
must be one of 'null' or 'list'
na
how to print NA values: must be one of 'null'
or 'string'. Defaults are class specific
auto.unbox
automatically unbox all atomic vectors
of length 1. It is usually safer to avoid this and instead use
the unbox function to unbox individual elements. An exception is
that objects of class AsIs (i.e. wrapped in I()) are not
automatically unboxed. This is a way to mark single values as
length-1 arrays. [as boolean]
digits
max number of decimal digits to print for
numeric values. Use I() to specify significant digits. Use NA
for max precision. [as integer]
pretty
adds indentation whitespace to JSON output.
Can be TRUE/FALSE or a number specifying the number of spaces
to indent. See prettify. [as boolean]
force
unclass/skip objects of classes with no
defined JSON mapping. [as boolean]
args
arguments passed on to class specific print
methods. [as list]
env
[as Environment]
Details
The toJSON and fromJSON functions are drop-in replacements for
the identically named functions in packages rjson and RJSONIO.
Our implementation uses an alternative, somewhat more
consistent mapping between R objects and JSON strings.
The serializeJSON and unserializeJSON functions in this package
use an alternative system to convert between R objects and JSON,
which supports more classes but is much more verbose.
A JSON string is always unicode, using UTF-8 by default, hence
there is usually no need to escape any characters. However,
the JSON format does support escaping of unicode characters,
which are encoded using a backslash followed by a lower case
"u" and 4 hex characters, for example: "Z\u00FCrich". The
fromJSON function will parse such escape sequences but it is
usually preferable to encode unicode characters in JSON using
native UTF-8 rather than escape sequences.
Authors
SMRUCC genomics
Value
this function returns data object of type
any kind.
clr value class
Examples
[Package
jsonlite version 6.0.0.3654
Index]