This function takes a list with person and time data and saves it into JSON bds format (which can be sent to JAMES).

write_bds(
  x = NULL,
  auto_format = TRUE,
  format = "3.0",
  schema = NULL,
  file = NULL,
  organisation = 0L,
  indent = NULL,
  check = TRUE,
  verbose = FALSE,
  ...
)

Arguments

x

List containing elements psn (persondata) and xyz (timedata) with data of the target child. See bdsreader:::make_target() for supported fields.

auto_format

Logical. Should a field Format be written to the result? Default is TRUE. Note: Only used for versions 1.0 and 1.1.

format

String. JSON data schema version number. There are currently three schemas supported: "1.0", "1.1", "2.0" and "3.0". Formats "1.0" and "1.1" are included for backward compatibility only. Use format = "3.0" for new applications.

schema

A file name (optionally including the path) with the JSON validation schema. The schema argument overrides format. The function extracts the version number for the basename, and overwrites the format argument by version number.

file

File name. The default (NULL) returns the json representation of the data and does not write to a file.

organisation

Integer. Organisation number of the caller. Optional.

indent

Integer. Number of spaces to indent when using jsonlite::prettify(). When not specified, the function writes minified json.

check

Logical. Should function check json to conform to schema?

verbose

Logical. Print file message?

...

Passed down to jsonlite::toJSON().

Value

A string with bds-formatted JSON codes, or NULL for invalid JSON

Details

Functions read_bds() and write_bds() are inverse operations.

If the date of birth is not known, the conversion uses the artificial birth date 01 Jan 2000 to calculate measurement dates from age.

Author

Stef van Buuren 2021

Examples

fn <- system.file("extdata/bds_v1.0/smocc/Laura_S.json",
  package = "jamesdemodata")
tgt <- read_bds(fn, format = "1.0", append_ddi = FALSE)
js1 <- write_bds(tgt, format = "1.0")
js2 <- write_bds(tgt, format = "2.0")
js3 <- write_bds(tgt)