j_schema_is_valid {rjsoncons}R Documentation

Validate JSON documents against JSON Schema

Description

j_schema_is_vaild() uses JSON Schema https://json-schema.org/ to validate JSON 'data' according to 'schema'.

j_schema_validate() returns a JSON or R object, data.frame, or tibble, describing how data does not conform to schema. See the "Using 'jsoncons' in R" vignette for help interpreting validation results.

Usage

j_schema_is_valid(
  data,
  schema,
  ...,
  data_type = j_data_type(data),
  schema_type = j_data_type(schema)
)

j_schema_validate(
  data,
  schema,
  as = "string",
  ...,
  data_type = j_data_type(data),
  schema_type = j_data_type(schema)
)

Arguments

data

JSON character vector, file, or URL defining document to be validated. NDJSON data and schema are not supported.

schema

JSON character vector, file, or URL defining the schema against which data will be validated.

...

passed to jsonlite::toJSON when data is not character-valued.

data_type

character(1) type of data; one of "json" or a value returned by j_data_type(); schema validation does not support "ndjson" data.

schema_type

character(1) type of schema; see data_type.

as

for j_schema_validate(), one of "string", "R", "data.frame", "tibble", or "details", to determine the representation of the return value.

Examples

## Allowable `data_type=` and `schema_type` -- excludes 'ndjson'
j_data_type() |>
    Filter(\(type) !"ndjson" %in% type, x = _) |>
    str()
## compare JSON patch to specification. 'op' key should have value
## 'add'; 'paths' key should be key 'path'
## schema <- "https://json.schemastore.org/json-patch.json"
schema <- system.file(package = "rjsoncons", "extdata", "json-patch.json")
op <- '[{
    "op": "adds", "paths": "/biscuits/1",
    "value": { "name": "Ginger Nut" }
}]'
j_schema_is_valid(op, schema)

j_schema_validate(op, schema, as = "details")


[Package rjsoncons version 1.3.0 Index]