Skip to contents

Serializes x to JSON by coercing it with as_vector() first.

Usage

to_json(x, ...)

Arguments

x

Any. Object to serialize.

...

Additional arguments passed to yyjsonr::write_json_str().

pretty

Bool. Whether to pretty-print the JSON output.

Value

A string containing JSON.

Examples

library(S7)
Point <- new_class(
  "Point",
  properties = list(x = class_float, y = class_float)
)
to_json(Point(1, 2))
#> [1] "{\"x\":1.0,\"y\":2.0}"