Create named list of options for serializing R to JSON

to_opts(
  dataframe = c("rows", "columns"),
  factor = c("string", "integer"),
  auto_unbox = FALSE,
  pretty = FALSE,
  name_repair = c("none", "minimal"),
  num_specials = c("null", "string"),
  str_specials = c("null", "string"),
  yyjson_write_flag = 0L
)

Arguments

dataframe

how to encode data.frame objects. Options 'rows' or columns'. Default: 'rows'

factor

how to encode factor objects: must be one of 'string' or 'integer' Default: 'string'

auto_unbox

automatically unbox all atomic vectors of length 1 such that they appear as atomic elements in JSON rather than arrays of length 1.

pretty

Logical value indicating if the created JSON string should have whitespace for indentation and linebreaks. Default: FALSE. Note: this option is equivalent to yyjson_write_flag = write_flag$YYJSON_WRITE_PRETTY

name_repair

How should unnamed items in a partially named list be handled? 'none' means to leave their names blank in JSON (which may not be valid JSON). 'minimal' means to use the integer position index of the item as its name if it is missing. Default: 'none'

num_specials

Should special numeric values (i.e. NA, NaN, Inf) be converted to a JSON null value or converted to a string representation e.g. "NA"/"NaN" etc. Default: 'null'

str_specials

Should a special value of NA in a character vector be converted to a JSON null value, or converted to a string "NA"? Default: 'null'

yyjson_write_flag

integer vector corresponding to internal yyjson options. See write_flag in this package, and read the yyjson API documentation for more information. This is considered an advanced option.

Value

Named list of options

See also

Examples

if (FALSE) {
to_json_str(iris, opts = to_opts(factor = 'integer'))
}