write_JSONSchema: Write a JSON Schema to file

View source: R/schema.R

write_JSONSchemaR Documentation

Write a JSON Schema to file

Description

Serializes a schema built as a named list and writes it, with the keywords in the registry's reading order. Every generator that publishes to schema.rtemis.org writes through this, so the documents share one shape.

Usage

write_JSONSchema(schema, file, overwrite = FALSE, digits = NA, verbosity = 1L)

Arguments

schema

Named list: The schema.

file

Character: Path to output JSON file.

overwrite

Logical: If TRUE, overwrite an existing file.

digits

Integer or NA: Significant digits for numeric values, passed to jsonlite::toJSON(). NA writes each number at full precision as R prints it. Pass I(17) where a value must round-trip an IEEE 754 double exactly: jsonlite's own default is 4 decimal places, which silently rounds, and a document that is nearly right is worse than one that is obviously wrong.

verbosity

Integer: Verbosity level.

Value

schema, invisibly.

Author(s)

EDG

Examples


schema <- list(
  `$schema` = "https://json-schema.org/draft/2020-12/schema",
  `$id` = "https://example.org/demo/v1/schema.json",
  title = "Demo",
  type = "object",
  properties = list(n = list(type = "integer", minimum = 1L))
)
tmpfile <- file.path(tempdir(), "demo.schema.json")
write_JSONSchema(schema, tmpfile, overwrite = TRUE, verbosity = 0L)


rtemis.core documentation built on Sept. 20, 2026, 9:06 a.m.