Validate a single json against a schema. This is a convenience wrapper around json_validator(schema)(json). See json_validator() for further details.

  verbose = FALSE,
  greedy = FALSE,
  error = FALSE,
  engine = "imjv",
  reference = NULL,
  query = NULL,
  strict = FALSE



Contents of a json object, or a filename containing one.


Contents of the json schema, or a filename containing a schema.


Be verbose? If TRUE, then an attribute "errors" will list validation failures as a data.frame


Continue after the first error?


Throw an error on parse failure? If TRUE, then the function returns NULL on success (i.e., call only for the side-effect of an error on failure, like stopifnot).


Specify the validation engine to use. Options are "imjv" (the default; which uses "is-my-json-valid") and "ajv" (Another JSON Schema Validator). The latter supports more recent json schema features.


Reference within schema to use for validating against a sub-schema instead of the full schema passed in. For example if the schema has a 'definitions' list including a definition for a 'Hello' object, one could pass "#/definitions/Hello" and the validator would check that the json is a valid "Hello" object. Only available if engine = "ajv".


A string indicating a component of the data to validate the schema against. Eventually this may support full jsonpath syntax, but for now this must be the name of an element within json. See the examples for more details.


Set whether the schema should be parsed strictly or not. If in strict mode schemas will error to "prevent any unexpected behaviours or silently ignored mistakes in user schema". For example it will error if encounters unknown formats or unknown keywords. See for details. Only available in engine = "ajv".


# A simple schema example:
schema <- '{
    "$schema": "",
    "title": "Product",
    "description": "A product from Acme\'s catalog",
    "type": "object",
    "properties": {
        "id": {
            "description": "The unique identifier for a product",
            "type": "integer"
        "name": {
            "description": "Name of the product",
            "type": "string"
        "price": {
            "type": "number",
            "minimum": 0,
            "exclusiveMinimum": true
        "tags": {
            "type": "array",
            "items": {
                "type": "string"
            "minItems": 1,
            "uniqueItems": true
    "required": ["id", "name", "price"]

# Test if some (invalid) json conforms to the schema
jsonvalidate::json_validate("{}", schema, verbose = TRUE)
#> [1] FALSE
#> attr(,"errors")
#>        field     message
#> 1 is required
#> 2 is required
#> 3 data.price is required

# Test if some (valid) json conforms to the schema
json <- '{
    "id": 1,
    "name": "A green door",
    "price": 12.50,
    "tags": ["home", "green"]
jsonvalidate::json_validate(json, schema)
#> [1] TRUE

# Test a fraction of a data against a reference into the schema:
jsonvalidate::json_validate(json, schema,
                            query = "tags", reference = "#/properties/tags",
                            engine = "ajv", verbose = TRUE)
#> [1] TRUE