JSON Schema in Go using Katydid underlying algorithm. This project translates JSON Schema to a regular hedge grammar and then executes validation via Katydid's validator-go.
import (
"katydid.org.za/go/validator-go-jsonschema/jsonschema"
)
func main() {
schemaBytes := []byte(`
{ "title": "small jsonschema for a blogpost",
"type":"object", "additionalProperties":false, "required": ["content"],
"properties": {
"content": { "type":"string" },
"author": { "$ref":"#/definitions/user-profile" } },
"definitions": { "user-profile": {
"type": "object", "additionalProperties":false, "required": ["username"],
"properties": {
"username": { "type":"string" },
"email": { "type":"string", "format":"email" } } } } }`)
compiled, err := jsonschema.Compile(schemaBytes)
...
input := []byte(`{"content": "Dragons", "author": {"username": "Khaleesi"}}`)
matched, err := compiled.MatchBytes(input)
...
}- Draft4 (excluding
uniqueItemsandremoteRef)