Versions in this module Expand all Collapse all v1 v1.0.0 May 4, 2026 Changes in this version + const DraftDefault + const OASBaseSchemaURL + const OASDialectURL + const VocabApplicator + const VocabContent + const VocabCore + const VocabFormatAnnot + const VocabFormatAssert + const VocabMetaData + const VocabOAS + const VocabUnevaluated + const VocabValidation + var ErrCompile = &CompileError + var ErrFormat = &FormatError + var ErrInstanceTooLarge = errors.New("jsonschema: instance exceeds size limit") + var ErrInvalidTOML = errors.New("jsonschema: invalid toml") + var ErrInvalidYAML = errors.New("jsonschema: invalid yaml") + var ErrLoader = &LoaderError + var ErrLoaderRejected = errors.New("jsonschema: loader rejected URI scheme") + var ErrMaxKeyCount = errors.New("jsonschema: max key count exceeded") + var ErrMaxRefDepth = errors.New("jsonschema: max ref depth exceeded") + var ErrMaxValidationDepth = errors.New("jsonschema: max validation depth exceeded") + var ErrNilReader = errors.New("jsonschema: nil reader") + var ErrRef = &RefError + var ErrRefCycle = errors.New("jsonschema: ref cycle detected") + var ErrSchemaNotCompiled = errors.New("jsonschema: schema not compiled") + var ErrUnknownDraft = errors.New("jsonschema: unknown draft") + var ErrUnknownFormat = errors.New("jsonschema: unknown format") + var ErrUnknownKeyword = errors.New("jsonschema: unknown keyword") + var ErrUnsupportedSchemaShape = errors.New("jsonschema: unsupported schema shape") + var ErrValidation = &ValidationError + var ErrValidationFailed = errors.New("jsonschema: validation failed") + func GenerateBytes(v any, opts ...GenerateOption) ([]byte, error) + func MetaSchemaBytes(d Draft) ([]byte, error) + func MetaSchemaURL(d Draft) string + func MustValidateTo[T any](schema *Schema, instanceJSON []byte, opts ...Option) T + func RenderError(schemaSrc, instanceSrc []byte, err error, color ...bool) string + func ValidateTo[T any](schema *Schema, instanceJSON []byte, opts ...Option) (T, error) + type Annotation struct + AbsoluteKeywordLocation string + InstanceLocation string + Keyword string + KeywordLocation string + Value any + type ChainLoader []Loader + func (c ChainLoader) Load(uri string) ([]byte, error) + type CompileError struct + Cause error + KeywordLocation string + Message string + func (e *CompileError) Error() string + func (e *CompileError) Is(target error) bool + func (e *CompileError) Unwrap() error + type CompileOption func(*compileOptions) + func WithBaseURI(uri string) CompileOption + func WithDefaultDraft(d Draft) CompileOption + func WithLoader(l Loader) CompileOption + func WithLoaderTrace(w io.Writer) CompileOption + func WithMaxRefDepth(n int) CompileOption + func WithMetaSchemaValidation(b bool) CompileOption + func WithRefCollisionPolicy(p RefCollisionPolicy) CompileOption + func WithStrict() CompileOption + func WithStrictKeywords(b bool) CompileOption + type Compiler struct + func NewCompiler(opts ...CompileOption) *Compiler + func (c *Compiler) AddResource(uri string, schemaJSON []byte) error + func (c *Compiler) Compile(schemaJSON []byte) (*Schema, error) + func (c *Compiler) CompileURL(uri string) (*Schema, error) + func (c *Compiler) CompileValue(v any) (*Schema, error) + func (c *Compiler) MustCompile(schemaJSON []byte) *Schema + func (c *Compiler) MustCompileURL(uri string) *Schema + func (c *Compiler) MustCompileValue(v any) *Schema + type Draft int + const Draft201909 + const Draft202012 + const Draft4 + const Draft6 + const Draft7 + const DraftUnknown + func DraftFromMetaSchemaURL(url string) Draft + func (d Draft) DefsKeyword() string + func (d Draft) IDKeyword() string + func (d Draft) MetaSchemaURL() string + func (d Draft) String() string + type EmbedLoader struct + FS embed.FS + func (l EmbedLoader) Load(uri string) ([]byte, error) + type FileLoader struct + Root string + func (l FileLoader) Load(uri string) ([]byte, error) + type FormatError struct + Cause error + Format string + Value string + func (e *FormatError) Error() string + func (e *FormatError) Is(target error) bool + func (e *FormatError) Unwrap() error + type FormatValidator func(string) error + type GenerateOption func(*generateOptions) + func WithCustomEmitter[T any](fn func(reflect.Type) *Schema) GenerateOption + func WithDocReader(src fs.FS) GenerateOption + func WithGenerateAdditionalPropertiesFalse(b bool) GenerateOption + func WithGenerateDraft(d Draft) GenerateOption + func WithGenerateDurationAsString(b bool) GenerateOption + func WithGenerateExpandedRefs(b bool) GenerateOption + func WithGenerateID(id string) GenerateOption + func WithGenerateInterfaceAsAny(b bool) GenerateOption + func WithGenerateNullablePointers(b bool) GenerateOption + func WithGenerateOmitDescriptions(b bool) GenerateOption + func WithGenerateOrderedProperties(b bool) GenerateOption + func WithGenerateSchemaDeclaration(b bool) GenerateOption + type Generator struct + func NewGenerator(opts ...GenerateOption) *Generator + func (g *Generator) FromType(t reflect.Type) (*Schema, error) + func (g *Generator) Generate(v any) (*Schema, error) + func (g *Generator) GenerateBytes(v any) ([]byte, error) + func (g *Generator) MustGenerate(v any) *Schema + type HTTPLoader struct + AllowHTTP bool + Cache time.Duration + Client *http.Client + MaxBodySize int64 + RequestDecorator func(*http.Request) + Timeout time.Duration + func (l *HTTPLoader) Load(uri string) ([]byte, error) + type Keyword interface + Name func() string + RetiredInDraft func() Draft + SinceDraft func() Draft + func KeywordsForDraft(d Draft) []Keyword + func LookupKeyword(name string, d Draft) (Keyword, bool) + type KeywordBinding struct + Location string + Name string + RawValue any + type Loader interface + Load func(uri string) ([]byte, error) + func DefaultLoader() Loader + type LoaderError struct + Cause error + URI string + func (e *LoaderError) Error() string + func (e *LoaderError) Is(target error) bool + func (e *LoaderError) Unwrap() error + type MapItem struct + Key string + Value any + type MapLoader map[string][]byte + func (m MapLoader) Load(uri string) ([]byte, error) + type MapSlice []MapItem + type Number = json.Number + type Option func(*runOptions) + func WithCollectAnnotations(b bool) Option + func WithContentAssertion(b bool) Option + func WithCustomFormat(name string, fn func(string) error) Option + func WithFormatAssertion(b bool) Option + func WithMaxDepth(n int) Option + func WithMaxDocumentSize(n int) Option + func WithMaxErrors(n int) Option + func WithMaxInstanceSize(n int) Option + func WithMaxKeyCount(n int) Option + func WithMaxValidationDepth(n int) Option + func WithReadOnly(b bool) Option + func WithStopOnFirstError(b bool) Option + func WithUnknownFormat(p UnknownFormatPolicy) Option + func WithWarningSink(w io.Writer) Option + func WithWriteOnly(b bool) Option + type OutputFormat int + const OutputBasic + const OutputDetailed + const OutputFlag + const OutputVerbose + func (f OutputFormat) String() string + type RefCollisionPolicy int + const RefCollisionError + const RefCollisionFirstWins + const RefCollisionLastWins + func (p RefCollisionPolicy) String() string + type RefError struct + BaseURI string + Cause error + Ref string + func (e *RefError) Error() string + func (e *RefError) Is(target error) bool + func (e *RefError) Unwrap() error + type Result struct + Annotations []Annotation + Errors []ValidationError + Valid bool + func Validate(schemaJSON, instanceJSON []byte, opts ...Option) (*Result, error) + func ValidateJSONC(s *Schema, data []byte, opts ...Option) (*Result, error) + func ValidateTOML(s *Schema, data []byte, opts ...Option) (*Result, error) + func ValidateYAML(s *Schema, data []byte, opts ...Option) (*Result, error) + func (r *Result) Output(format OutputFormat) []byte + type Schema struct + func Compile(schemaJSON []byte, opts ...CompileOption) (*Schema, error) + func CompileURL(uri string, opts ...CompileOption) (*Schema, error) + func CompileValue(schemaValue any, opts ...CompileOption) (*Schema, error) + func FromType(t reflect.Type, opts ...GenerateOption) (*Schema, error) + func Generate(v any, opts ...GenerateOption) (*Schema, error) + func LoadJSON(schemaJSON []byte, opts ...CompileOption) (*Schema, error) + func LoadJSONC(schemaJSONC []byte, opts ...CompileOption) (*Schema, error) + func LoadJSONCURL(uri string, opts ...CompileOption) (*Schema, error) + func LoadJSONCValue(v any, opts ...CompileOption) (*Schema, error) + func LoadJSONURL(uri string, opts ...CompileOption) (*Schema, error) + func LoadJSONValue(v any, opts ...CompileOption) (*Schema, error) + func LoadTOML(schemaTOML []byte, opts ...CompileOption) (*Schema, error) + func LoadTOMLURL(uri string, opts ...CompileOption) (*Schema, error) + func LoadTOMLValue(v any, opts ...CompileOption) (*Schema, error) + func LoadYAML(schemaYAML []byte, opts ...CompileOption) (*Schema, error) + func LoadYAMLURL(uri string, opts ...CompileOption) (*Schema, error) + func LoadYAMLValue(v any, opts ...CompileOption) (*Schema, error) + func MetaSchema(d Draft) (*Schema, error) + func MustCompile(schemaJSON []byte, opts ...CompileOption) *Schema + func MustCompileURL(uri string, opts ...CompileOption) *Schema + func MustCompileValue(schemaValue any, opts ...CompileOption) *Schema + func MustGenerate(v any, opts ...GenerateOption) *Schema + func MustLoadJSON(schemaJSON []byte, opts ...CompileOption) *Schema + func MustLoadJSONC(schemaJSONC []byte, opts ...CompileOption) *Schema + func MustLoadJSONCURL(uri string, opts ...CompileOption) *Schema + func MustLoadJSONCValue(v any, opts ...CompileOption) *Schema + func MustLoadJSONURL(uri string, opts ...CompileOption) *Schema + func MustLoadJSONValue(v any, opts ...CompileOption) *Schema + func MustLoadTOML(schemaTOML []byte, opts ...CompileOption) *Schema + func MustLoadTOMLURL(uri string, opts ...CompileOption) *Schema + func MustLoadTOMLValue(v any, opts ...CompileOption) *Schema + func MustLoadYAML(schemaYAML []byte, opts ...CompileOption) *Schema + func MustLoadYAMLURL(uri string, opts ...CompileOption) *Schema + func MustLoadYAMLValue(v any, opts ...CompileOption) *Schema + func OutputMetaSchema() *Schema + func (s *Schema) Anchors() []string + func (s *Schema) Bindings() []KeywordBinding + func (s *Schema) Draft() Draft + func (s *Schema) ID() string + func (s *Schema) MarshalJSON() ([]byte, error) + func (s *Schema) MetaSchemaURI() string + func (s *Schema) Resources() []string + func (s *Schema) String() string + func (s *Schema) Validate(instanceJSON []byte, opts ...Option) (*Result, error) + func (s *Schema) ValidateAndUnmarshal(instanceJSON []byte, v any, opts ...Option) error + func (s *Schema) ValidateReader(r io.Reader, opts ...Option) (*Result, error) + func (s *Schema) ValidateValue(v any, opts ...Option) (*Result, error) + func (s *Schema) Vocabularies() []string + type UnknownFormatPolicy int + const UnknownFormatError + const UnknownFormatIgnore + const UnknownFormatWarn + func (p UnknownFormatPolicy) String() string + type ValidationError struct + AbsoluteKeywordLocation string + Cause error + Causes []ValidationError + InstanceLocation string + Keyword string + KeywordLocation string + Message string + func (e *ValidationError) Error() string + func (e *ValidationError) Is(target error) bool + func (e *ValidationError) Unwrap() []error + type Vocabulary struct + Keywords []Keyword + URI string + func Vocabularies() []Vocabulary