JSON Schema implementation in Erlang and standalone validation server.
- Basic server logic
- Basic validation logic
- Constraints
- Schema builder
- Schema validation
- Put your schemas in
webrootdirectory. May use subdirectories too. (Great tool for generating JSON schema from JSON) - Start server (it listens on port 5000 by default, can be changed in
etc/app.config) GETrequest will receive schema from server. Possible responses:HTTP 200 OK(schema in response body)HTTP 404 Schema not foundHTTP 500 Broken schemaPOSTrequest will validate JSON sent as request body. Possible responses:HTTP 200 OK(JSON validates against schema)HTTP 404 Schema not foundHTTP 460 Invalid input(input is not a valid JSON)HTTP 461 Invalid JSON(JSON does not validates against schema)HTTP 500 Broken schemaResponse will contain JSON-encoded array of validation errors or empty array if validation passes.
Let's assume that webroot directory has following structure:
webroot
|-- schemas_v1
| |-- schema1.jsonschema
| +-- schema2.jsonschema
|
+-- schemas_v2
|-- schema1.jsonschema
+-- schema2.jsonschema
- Request
GET localhost:5000/schemas_v1/schema1.jsonschemawill receivewebroot/schemas_v1/schema1.jsonschema - Request
POST localhost:5000/schemas_v1/schema1.jsonschemawill validate posted JSON against schema inwebroot/schemas_v1/schema1.jsonschemafile and return validation errors in response.
You may use JSON Validator as library. Required sources are jvalidator_validator.erl and all constraint_*.erl files.
To perform validation you need to decode your JSON and JSON schema by mochijson2:decode/1 function
and pass them to jvalidator_validator:validate/2 function.
Json2 = mochijson2:decode(Json),
Schema2 = mochijson2:decode(Schema),
ValidationErrors = jvalidator_validator:validate(Json2, Schema2).