| write_json | R Documentation |
Serialize a data frame to a CDISC Dataset-JSON v1.1 (.json) file,
Dataset-JSON being the native home of the artoo_meta shape: the file is
the metadata block plus a flat rows array. The emit end of the artoo
workflow (spec -> apply_spec -> write_json); a thin wrapper over
write_dataset() with format = "json".
write_json(
x,
path,
on_invalid = c("error", "translit", "fold", "replace", "ignore"),
created = NULL,
strict = FALSE
)
x |
The dataset to write. |
path |
Destination |
on_invalid |
Policy for values that are not valid UTF-8.
|
created |
Creation timestamp. |
strict |
Suppress the Note: |
Full metadata, no loss. Unlike .xpt, a .json file records the
complete artoo_meta: keySequence, codelist, origin, targetDataType, and
significantDigits all survive. Dates, datetimes, and times are exchanged as
ISO 8601 strings, or as SAS-epoch numbers when their targetDataType is
"integer" (the ADaM numeric-date convention); decimal rides as a string
so exact precision is preserved. The file is always UTF-8 (RFC 8259 / CDISC
v1.1). NaN and infinite values are not valid CDISC numerics and abort the
write.
Streaming write, whole-file read. The writer streams the rows array
in bounded slabs (a .json.gz path gzips the stream transparently), but
read_json() must parse the whole array at once. For multi-million-row
datasets prefer the NDJSON variant (write_ndjson() / read_ndjson()),
which bounds memory in both directions.
The input x, invisibly, so a write can sit mid-pipeline.
read_json() for the inverse; write_dataset() for the generic
dispatcher.
# ---- Example 1: write a conformed dataset as Dataset-JSON ----
#
# apply_spec() attaches the metadata; write_json() serializes the full
# itemGroup plus the data rows.
adsl <- apply_spec(cdisc_adsl, adam_spec, "ADSL", conformance = "off")
path <- tempfile(fileext = ".json")
write_json(adsl, path)
# ---- Example 2: a frozen timestamp for reproducible bytes ----
#
# Fixing `created` makes two writes byte-identical; the columns() pane on
# the written file shows the full metadata the file carries (DM is SDTM,
# so it conforms against the bundled sdtm_spec).
dm <- apply_spec(cdisc_dm, sdtm_spec, "DM", conformance = "off")
path2 <- tempfile(fileext = ".json")
write_json(dm, path2, created = as.POSIXct("2020-01-01", tz = "UTC"))
columns(path2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.