jsonschema

package
v0.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 15, 2026 License: Apache-2.0 Imports: 8 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonschema validates structured agent answers against the subset of JSON Schema the profile's schemas may use: type, properties, required, additionalProperties, enum, minLength, maxLength, minItems, maxItems, items, pattern (RE2) and description. Compile refuses every other keyword, naming the field.

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("does not fit the schema")

ErrInvalid is wrapped by every error Validate returns.

View Source
var ErrSchema = errors.New("jsonschema: unsupported schema")

ErrSchema is wrapped by every error Compile returns.

View Source
var Keywords = []string{"type", "properties", "required", "additionalProperties", "enum", "minLength", "maxLength",
	"minItems", "maxItems", "items", "pattern", "description"}

Keywords are the JSON Schema keywords Compile accepts.

View Source
var Types = []string{"object", "array", "string", "integer", "number", "boolean", "null"}

Types are the values of type Compile accepts.

Functions

This section is empty.

Types

type Options

type Options struct {
	// Flat refuses an object nested below the top level, as the brief
	// intent's extra schema must be.
	Flat bool
}

Options narrow what Compile accepts.

type Property

type Property struct {
	Name string
	// Type is the property's type.
	Type string
	// Items is the type of an array property's items.
	Items string
	// Enum are the string values of the property, or of its items.
	Enum []string
	// Source is the property's own schema bytes, which its field version
	// hashes.
	Source []byte
}

Property is one top-level property of a flat object schema, as a fact reads it.

type Schema

type Schema struct {
	// contains filtered or unexported fields
}

Schema is a compiled schema.

func Compile

func Compile(src []byte, o Options) (*Schema, error)

Compile parses src, refusing a keyword outside Keywords or, with Flat, a nested object; the error names the field.

func (*Schema) Properties

func (s *Schema) Properties() []Property

Properties are the top-level properties of an object schema, by name.

func (*Schema) Source

func (s *Schema) Source() []byte

Source is the schema as written.

func (*Schema) Validate

func (s *Schema) Validate(v any) error

Validate checks a decoded JSON value against s; the error names the first field that does not fit.

func (*Schema) ValidateJSON

func (s *Schema) ValidateJSON(raw []byte) error

ValidateJSON decodes raw and validates it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL