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 |
... |
passed to |
data_type |
character(1) type of |
schema_type |
character(1) type of |
as |
for |
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")