Build Status GoDoc API

yajsonschema (Yet Another JSON Schema [something]) is a tool which converts a schema written in the yaml format defined here into a proper JSON Schema (draft-04). i.e. it’s primarily an easier way to write json schemas, but you can also use it directly as a validator.

It tries to be as easy as possible to use by starting from the idea that a normal document should act as its own schema (i.e. should match itself).

WARNING: this is largely ‘proof-of-concept’ and hasn’t been used beyond the test-cases.

Example schema

---
name: !type {
  type: string,
  minLength: 1
}
---
fileType: !enum [json, yaml]
organisation: !ref name
evil?: !type boolean
people:
- name: !ref name
  age: !type {
    type: integer,
    min: 0
  }
  -: false # definition of JSON Schema additionalProperties
- funkiness: true

Things you may notice here:

Using as a Go library

See usage in cmd/yajsonschema.go and API documentation on godoc

Using as a CLI tool

To generate the json schema (on stdout):

yajsonschema -s schema.yaml

To validate json documents immediately:

yajsonschema -s schema.yaml myinput.json myinput2.json

(error code of 2 indicates failure to validate; output on stderr)

Similar work

There’re a bunch other validators and ‘json schema generators’. I don’t know of any others that rely on yaml custom types like this, or are inspired explicitly by the idea of being as close as possible to the input (i.e. such that one can use input as a validation schema, and can develop a schema by ‘relaxing’ an example input appropriately).

TODO