jsonschema

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package jsonschema derives, parses, and validates JSON Schema contracts.

Example
package main

import (
	"fmt"

	"github.com/Tangerg/scope/core/jsonschema"
)

func main() {
	type answer struct {
		Value int `json:"value"`
	}
	schema, err := jsonschema.For[answer]()
	if err != nil {
		panic(err)
	}

	fmt.Println(schema.Validate([]byte(`{"value":42}`)))
}
Output:
<nil>

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrInvalid = errors.New("jsonschema: invalid schema")

Functions

This section is empty.

Types

type Modeler

type Modeler interface {
	// JSONSchemaModel returns a non-nil typed value whose encoding/json wire shape
	// exactly matches the receiver's custom encoding. The concrete model type is
	// part of the schema contract and must remain stable across calls.
	JSONSchemaModel() any
}

Modeler is implemented by rich values whose encoding/json representation is described by a separate typed model. Implementations must return the same non-nil model type on every call.

type Schema

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

Schema is an immutable, compiled JSON Schema. Its zero value is invalid and successfully constructed values are safe for concurrent validation.

func For

func For[T any]() (Schema, error)

For derives and compiles the JSON Schema contract for T. It follows encoding/json field names and options and the invopop/jsonschema tag dialect. Structs reject additional properties by default.

func Parse

func Parse(raw []byte) (Schema, error)

Parse validates, compiles, and takes ownership of one JSON Schema document.

func (Schema) JSON

func (s Schema) JSON() json.RawMessage

func (Schema) MarshalJSON

func (s Schema) MarshalJSON() ([]byte, error)

func (*Schema) UnmarshalJSON

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

func (Schema) Valid

func (s Schema) Valid() bool

func (Schema) Validate

func (s Schema) Validate(raw []byte) error

Jump to

Keyboard shortcuts

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