GeoMongo (version 1.0.1)

json_schema_validator: 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.python.org/pypi/jsonschema, http://python-jsonschema.readthedocs.io/en/latest/

Examples

Run this code
# NOT RUN {
library(GeoMongo)

if (reticulate::py_available() && reticulate::py_module_available("jsonschema")) {

 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)

}

# }

Run the code above in your browser using DataCamp Workspace