schemajson

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2026 License: MIT Imports: 6 Imported by: ? modules, 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 schemajson parses immutable, ordered JSON documents without losing native schema syntax, number precision, or escaped UTF-16 code units.

Index

Constants

View Source
const DefaultBytes = 16 * 1024 * 1024
View Source
const DefaultDepth = 256
View Source
const DefaultNodes = 1000000

Variables

This section is empty.

Functions

func Fold

func Fold[R any](k Kind, cs KindCases[R]) R

Fold reduces Kind by one-level case analysis.

func KindEqual

func KindEqual(a, b Kind) bool

KindEqual reports structural equality of a and b.

func KindEqualWith

func KindEqualWith(a, b Kind, ov KindEqOverrides) bool

KindEqualWith reports structural equality of a and b under ov.

func KindName

func KindName(kind Kind) string

Types

type Array

type Array struct{}

type Boolean

type Boolean struct{}

type Document

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

func Parse

func Parse(input []byte, limits Limits) (Document, error)

Parse rejects duplicate decoded keys at every nesting level. It preserves the original bytes for unmodified export and never resolves references or accesses the network/filesystem. This is syntax ingestion, not schema validity.

func (Document) At

func (d Document) At(pointer string) (Node, error)

At looks up an existing node by a JSON Pointer. Empty means the document root. Array indexes are canonical nonnegative decimals; '-' is not a lookup.

func (Document) Raw

func (d Document) Raw() string

func (Document) Replace

func (d Document) Replace(pointer string, replacement []byte) (Document, error)

Replace returns a new document, changing only the selected node's source span. Other bytes (including unrelated native constraints) remain untouched. It replaces existing values, not member names or missing members. This is the lossless editing primitive, not a claim of schema-level compatibility.

func (Document) Root

func (d Document) Root() Node

type Error

type Error struct {
	Code    string `json:"code"`
	Offset  int    `json:"offset"`
	Path    string `json:"path"`
	Message string `json:"message"`
}

func (*Error) Error

func (e *Error) Error() string

type Kind

type Kind interface {
	// contains filtered or unexported methods
}

type KindCases

type KindCases[R any] struct {
	Object  func() R
	Array   func() R
	String  func() R
	Number  func() R
	Boolean func() R
	Null    func() R
}

KindCases selects one handler per Kind variant for Fold.

type KindEqOverrides

type KindEqOverrides struct {
	Object  func(x, y Object) (eq, handled bool)
	Array   func(x, y Array) (eq, handled bool)
	String  func(x, y String) (eq, handled bool)
	Number  func(x, y Number) (eq, handled bool)
	Boolean func(x, y Boolean) (eq, handled bool)
	Null    func(x, y Null) (eq, handled bool)
}

KindEqOverrides carries optional per-variant hooks for KindEqualWith. A hook returning handled=false falls through to the derived comparison.

type Limits

type Limits struct {
	Bytes int
	Depth int
	Nodes int
}

Limits protect ingestion separately from predicate evaluation. Zero values select defaults; an explicit positive value configures each resource cap.

type Member

type Member struct {
	Key   value.Text
	Value Node
}

type Node

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

Node retains an exact source slice. Its data cannot be mutated through public accessors, including ordered object members and array elements.

func (Node) ElementCount

func (n Node) ElementCount() int

ElementCount reports array cardinality before a defensive Elements copy.

func (Node) Elements

func (n Node) Elements() []Node

func (Node) Kind

func (n Node) Kind() Kind

func (Node) Lookup

func (n Node) Lookup(key string) (Node, bool)

func (Node) LookupText

func (n Node) LookupText(key value.Text) (Node, bool)

func (Node) MemberCount

func (n Node) MemberCount() int

MemberCount reports object cardinality without copying the immutable member slice, allowing allocation preflight before Members.

func (Node) Members

func (n Node) Members() []Member

func (Node) Raw

func (n Node) Raw() string

func (Node) Text

func (n Node) Text() (value.Text, bool)

type Null

type Null struct{}

type Number

type Number struct{}

type Object

type Object struct{}

type String

type String struct{}

Jump to

Keyboard shortcuts

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