Skip to content
/ ajv Public

❗ This is a read-only mirror of the CRAN R package repository. ajv — Another JSON Schema Validator. Homepage: https://github.com/jdthorpe/ajvr Report bugs for this package: https://github.com/jdthorpe/ajvr/issues

Notifications You must be signed in to change notification settings

cran/ajv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

The 'ajv' R library

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.

Installation

# install.packages("devtools") # (if not already installed)
devtools::install_github("jdthorpe/ajvr")

Getting started

The fastest validation call:

library('ajv')
var ajv = Ajv() # options can be passed, e.g. list(allErrors= TRUE)
var validate = ajv$compile(schema)
var valid = validate(data)
if (!valid) print(validate$errors)

or with less code

# ...
var valid = ajv$validate(schema, data)
if (!valid) print(ajv$errors)
# ...

or

# ...
ajv$addSchema(schema, 'mySchema')
var valid = ajv$validate('mySchema', data)
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.

About

❗ This is a read-only mirror of the CRAN R package repository. ajv — Another JSON Schema Validator. Homepage: https://github.com/jdthorpe/ajvr Report bugs for this package: https://github.com/jdthorpe/ajvr/issues

Resources

Stars

Watchers

Forks

Packages

No packages published