check_schema_json: Check data against a JSON Schema

View source: R/check-schema-json.R

check_schema_jsonR Documentation

Check data against a JSON Schema

Description

Check a JSON blob against a JSON Schema.

Usage

check_schema_json(
  json,
  schema,
  success_msg = "Data is valid against the schema",
  fail_msg = "Data is invalid against the schema"
)

Arguments

json

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

schema

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

success_msg

Message indicating the check succeeded.

fail_msg

Message indicating the check failed.

Value

A condition object indicating whether the data is valid against the schema.

Examples

if (requireNamespace("jsonvalidate", quietly = TRUE)) {
  schema <- '{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "properties": {
    "x": {
      "type": "integer"
    }
  },
  "required": ["x"]
}
'
  json_valid <- '{
  "x": 3
}'
  json_invalid <- '{
  "x": 1.5
}'
  check_schema_json(json_valid, schema)
  check_schema_json(json_invalid, schema)
}

Sage-Bionetworks/dccvalidator documentation built on May 7, 2022, 10:32 a.m.