Skip to content
This repository has been archived by the owner on Nov 23, 2017. It is now read-only.
/ judge-jsen Public archive

Small express server which accepts POST requests with JSON payloads and validates the contents vs a provided JSON Schema

License

Notifications You must be signed in to change notification settings

brentsmith-dev/judge-jsen

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Judge Jsen

judge-jsen is a tiny service intended to allow easy validation of JSON payloads using a provided JSON schema. It uses the excellent jsen validation tool.

Conventions

For judge-jsen to rule on a JSON payload it must first know what schema it is supposed to be using to validate against. This is done by requiring the root object of the JSON payload contain a $schema property with a url to the schema to be validated against.

example payload:

{
  "$schema": "https://raw.githubusercontent.com/statuswoe/judge-jsen/master/demo/demo.schema.json",
  "testString": "this is a test",
  "testInt": 12345
}

contents of schema at https://raw.githubusercontent.com/statuswoe/judge-jsen/master/demo/demo.schema.json

{
  "$schema": "http://json-schema.org/draft-04/schema#",
  "type": "object",
  "properties": {
    "$schema": {
      "type": "string"
    },
    "testString": {
      "type": "string"
    },
    "testInt": {
      "type": "integer"
    }
  },
  "additionalProperties": false,
  "required": [
    "$schema",
    "testString",
    "testInt"
  ]
}

Usage

Simply check out the source and run

npm install
node src/app.js

to start the service. Then you should be able to send POST requests to http://localhost:8000/validate to test the service.

curl -H "Accept: application/json" -H "Content-Type: application/json" --data-binary '{"$schema": "https://raw.githubusercontent.com/statuswoe/judge-jsen/master/demo/demo.schema.json", "testString": "this is a test", "testInt": 12345}' --compressed "http://localhost:8000/validate"

Responses to POST requests with valid schemas and a conforming JSON object should return a 200 response with a body similar to

data conforms to provided schema

Responses to POST requests with valid schemas but a non-conforming JSON object should return a 400 response with a body similar to

data does not conform to provided schema: [{"path":"testInt","keyword":"type"}]

where the error returns the first instance of non-conformity with the schema

Demo

An instance of this service may be available on heroku which can be used as a demo. To see the result you can use the following curl request:

curl -H "Accept: application/json" -H "Content-Type: application/json" --data-binary '{"$schema": "https://raw.githubusercontent.com/statuswoe/judge-jsen/master/demo/demo.schema.json", "testString": "this is a test", "testInt": 12345}' --compressed "https://judge-jsen.herokuapp.com/validate"

Notes

Currently the service only supports dereferenced JSON schemas
This project is still in the early stages of development

About

Small express server which accepts POST requests with JSON payloads and validates the contents vs a provided JSON Schema

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published