Task-oriented guides for building, validating against, and generating code from JSON Schema 2020-12 documents in Go.
If you would rather read code, every file under examples/ is a runnable go test example.
- Getting Started — install, and the build → compile → validate flow
- Building Schemas — the fluent builder, convenience constructors, loading from JSON
- Validating Data — compiling validators, reading errors, tracing
- References —
$ref,$id,$anchor,$dynamicRef, and the resolver - Vocabularies & the Meta-Schema — turning
formatinto an assertion, validating that a document is a schema - Code Generation — emitting pre-compiled validator code
- Command Line Tool —
lintandgen-validator - FAQ
schema package validator package
───────────── ─────────────────
*schema.Schema ──────▶ validator.Compile(ctx, schema) ──────▶ validator.Interface
(inert data) (compiles once) (run many times)
A schema is pure data — you build it or unmarshal it from JSON. To validate, you compile it into a validator.Interface and call Validate. Schemas never validate themselves; there is no schema.Validate.
Full API docs: https://pkg.go.dev/github.com/lestrrat-go/json-schema.