json_schema_validator {GeoMongo} | R Documentation |
simple way to validate a json instance under a given schema
Description
simple way to validate a json instance under a given schema
Usage
json_schema_validator(json_data = NULL, json_schema = NULL)
Arguments
json_data |
a named list specifying the input data to validate against the json-schema |
json_schema |
a named list specifying the json-schema |
Details
Define a json-schema that the input data should follow and then validate the input data against the schema. If the input data follows the schema then by running the function nothing will be returned, otherwise an error with Traceback will be printed in the R-session.
In case that type is at the same time also a property name in the json data, then do not include "type" = "string" in the json schema ( https://github.com/epoberezkin/ajv/issues/137 )
References
https://pypi.org/project/jsonschema/, https://python-jsonschema.readthedocs.io/en/latest/
Examples
try({
if (reticulate::py_available(initialize = FALSE)) {
if (reticulate::py_module_available("jsonschema")) {
library(GeoMongo)
schema_dict = list("type" = "object",
"properties" = list(
"name" = list("type" = "string"),
"location" = list("type" = "object",
"properties" = list(
"type" = list("enum" = c("Point", "Polygon")),
"coordinates" = list("type" = "array")
))))
data_dict = list("name" = "example location",
"location" = list("type" = "Point", "coordinates" = c(-120.24, 39.21)))
json_schema_validator(json_data = data_dict, json_schema = schema_dict)
}
}
}, silent=TRUE)
[Package GeoMongo version 1.0.3 Index]