The hardware and bandwidth for this mirror is donated by METANET, the Webhosting and Full Service-Cloud Provider.
If you wish to report a bug, or if you are interested in having us mirror your free-software or open-source project, please feel free to contact us at mirror[@]metanet.ch.
The ajv
library is a very thin wrapper around the
awesome AJV JSON
validation library. The essential change between the syntax presented in
the official AJV Readme
is exchanging JavaScript’s dot operator (.
) with R’s
dollar-sign operator ($
).
Note that care must be taken in transforming R objects to JSON,
because of R’s everything-is-a-vector philosopy. Hence, for convenience
file paths to valid JSON (.json
) and YAML
(.yml
or .yaml
) may be used wherever an object
is expected.
# install.packages("devtools") # (if not already installed)
::install_github("jdthorpe/ajvr") devtools
The fastest validation call:
library('ajv')
= Ajv() # options can be passed, e.g. list(allErrors= TRUE)
var ajv = ajv$compile(schema)
var validate = validate(data)
var valid if (!valid) print(validate$errors)
or with less code
# ...
= ajv$validate(schema, data)
var valid if (!valid) print(ajv$errors)
# ...
or
# ...
$addSchema(schema, 'mySchema')
ajv= ajv$validate('mySchema', data)
var valid if (!valid) print(ajv$errorsText())
# ...
Note that in each of these calls, schema
and
data
arguments may be a valid JSON string, an R object
(i.e. list(...)
), a connection to a JSON file, or the file
name of JSON or YAML file. YAML files are parsed via js-yaml’s
safeLoad()
method.
See API and Options for more details.
These binaries (installable software) and packages are in development.
They may not be fully stable and should be used with caution. We make no claims about them.