The JSON Validation Service (JVS) is a validator that allows a user to check JSON objects for compliance with the JSON grammar according to RFC 7159§.
- Plain API
- Easy to deploy using provided
Dockerfile
- Supports configurable logging based on Java Logging API via
logging.properties
file
JSONValidationService service;
try {
service = new JSONValidationService(); // use default parameters
service.start();
} catch (JVSException e) {
LOG.log(Level.SEVERE, "Service exception", e);
}
You have several ways to build JVSOptions
and pass it to the JSONValidationService
class constructor.
/* use default options */
JVSOptions options1 = new JVSOptions();
/* populate parameters from the configuration file */
JVSOptions options2 = new JVSOptions("config.file");
/* manually build your JVSOptions instance */
JVSOptions options3 = new JVSOptionsBuilder("localhost", 8081)
.setPath("/app")
.build();
/* or tune parameters from the file at runtime */
JVSOptions options4 = new JVSOptions("config")
.newBuilder()
.setPort(8080)
.setDelay(32)
.build()
/* and use like this */
new JSONValidationService(options4);
The configuration file is in JSON format with the following fields:
host
- a hostname or an IP address for the service to bindport
- a port number that is used by the servicebacklog
- a maximum number of incoming TCP connectionspath
- a location of the service on a given hostdelay
- the maximum time in seconds to wait until exchanges are finished
See jvs.properties file for an example.
-
If a received JSON is valid it is formatted to human-readable form and sent back.
-
If data in a request do not conform to the JSON grammar, the following response is sent:
{ "errorCode" : 12, "errorMessage" : "plain language description of the problem", "errorPlace" : "the point where error has occurred", "resource" : "filename taken from a URI", "request-id" : "the request id for easier tracking of errors" }
Below is a list of known errors:
Code | Meaning |
---|---|
1 | Unterminated array |
2 | Unterminated object |
3 | Expected name |
4 | Expected ':' |
5 | Unexpected value |
6 | Expected value |
7 | Unterminated string |
8 | Unterminated comment |
9 | Malformed JSON |
10 | Unterminated escape sequence |
11 | Invalid escape sequence |
12 | JSON forbids NaN and infinities |
Normally, JVS sends HTTPS OK
responses with Content-Type: application/json
in either case.
Run and build the Docker image:
$ cd "the path where the Dockerfile is placed"
$ docker build -t jvs .
$ docker run --rm -d -p 80:80 jvs
Or you can fork this project, change it as you want to, and commit the changes. Then you can simply run:
$ docker run --rm -d -p 80:80 jvs https://example.com/your_repo.git
To test that JVS is working properly, make a POST request as shown below:
$ cat file.json # example of a JSON file
{
"key" : "value"
}
$ curl -s --data-binary @file.json http://example.com[:port]/file.json
This project is licensed under the MIT License - see the LICENSE file for details
- The project is based on Google Gson library