Description Usage Arguments Details References Examples
simple way to validate a json instance under a given schema
1 | json_schema_validator(json_data = NULL, json_schema = NULL)
|
json_data |
a named list specifying the input data to validate against the json-schema |
json_schema |
a named list specifying the json-schema |
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 )
https://pypi.org/project/jsonschema/, https://python-jsonschema.readthedocs.io/en/latest/
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.