Skip to contents

Writes a data frame to a CDISC Dataset-JSON v1.1 file following the official CDISC specification. Column labels, types, and lengths are extracted from attributes set by set_label(), set_length(), or apply_spec(). If the herald.sort_keys attribute is set (e.g., by apply_spec() or sort_keys()), the data is sorted before writing. JSON is always UTF-8.

Usage

write_json(
  x,
  file,
  dataset = NULL,
  label = NULL,
  study_oid = "",
  metadata_version_oid = "",
  metadata_ref = NULL,
  originator = "herald"
)

Arguments

x

A data frame.

file

Output file path (should end in .json).

dataset

Dataset name (e.g., "DM"). Default: inferred from the "dataset_name" attribute or the file name.

label

Dataset label. Default: from the "label" attribute.

study_oid

Study OID for metadata. Default: "".

metadata_version_oid

Metadata version OID. Default: "".

metadata_ref

Path to define.xml. Default: NULL.

originator

Originator name. Default: "herald".

Value

x invisibly (the input data frame, not the file path).

See also

read_json() for reading, write_xpt() for XPT I/O, apply_spec() to decorate before writing.

Other io: json_to_xpt(), read_json(), xpt_to_json()

Examples

dm <- data.frame(
  STUDYID = c("STUDY1", "STUDY1"),
  USUBJID = c("SUBJ01", "SUBJ02"),
  AGE = c(65L, 72L),
  stringsAsFactors = FALSE
)
file <- tempfile(fileext = ".json")
write_json(dm, file, dataset = "DM", label = "Demographics")
unlink(file)