jsontext

package
v1.5.3 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 11 Imported by: 0 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 jsontext preserves exact JSON string identities, including escaped unpaired UTF16 units, while delegating JSON grammar and typed binding to established parsers. Persisted and wire output is always standard JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendString

func AppendString(buf []byte, s string) []byte

AppendString appends one JSON string without HTML escaping, preserving exact UTF16 units and retaining allocation-free appends when capacity permits.

func Marshal

func Marshal(value any) ([]byte, error)

Marshal encodes standard JSON. Existing valid strings retain standard Go JSON escaping; newly admitted lone UTF16 units use their standard \uXXXX spelling.

func Unmarshal

func Unmarshal(raw []byte, out any, stages ...DecodeStage) error

func UnmarshalValue

func UnmarshalValue(raw []byte) (any, error)

UnmarshalValue requires a complete generic JSON value and retains exact number lexemes rather than rounding integers through float64.

Types

type DecodeStage

type DecodeStage uint8

Unmarshal binds a complete standard JSON value without normalizing escaped lone UTF16 units into replacement characters. Numeric typed binding is fixed by the destination; dynamic exact-number fields use NumberMap or NumberList.

const (
	RawInput DecodeStage = iota
	ProjectedInput
)

type Decoder

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

Decoder uses the standard parser to frame one original JSON value. Decode preserves first-value stream behavior and leaves trailing-value policy to its caller. Buffered exposes bytes already read beyond the completed value.

func NewDecoder

func NewDecoder(reader io.Reader) *Decoder

func (*Decoder) Buffered

func (d *Decoder) Buffered() io.Reader

func (*Decoder) Decode

func (d *Decoder) Decode(out any) error

func (*Decoder) DecodeValue

func (d *Decoder) DecodeValue() (any, error)

DecodeValue reads one generic JSON tree with exact Number values. It does not consume a following value; callers requiring complete input check EOF.

func (*Decoder) DisallowUnknownFields

func (d *Decoder) DisallowUnknownFields()

DisallowUnknownFields rejects object fields absent from a typed destination.

func (*Decoder) InputOffset

func (d *Decoder) InputOffset() int64

type Encoder

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

Encoder writes one standard JSON value followed by a newline. It preserves first-write errors and supports the standard HTML escaping selection.

func NewEncoder

func NewEncoder(writer io.Writer) *Encoder

func (*Encoder) Encode

func (e *Encoder) Encode(value any) error

func (*Encoder) SetEscapeHTML

func (e *Encoder) SetEscapeHTML(enabled bool)

type NumberDecoder

type NumberDecoder struct{ Decoder }

NumberDecoder is a lossless typed stream whose dynamic numbers stay lexemes. It shares Decoder's framing and lifetime; it exposes no mutable number mode. Domain normalization belongs to the caller, not this JSON mechanism.

func NewNumberDecoder

func NewNumberDecoder(reader io.Reader) *NumberDecoder

func (*NumberDecoder) Decode

func (d *NumberDecoder) Decode(out any) error

type NumberList

type NumberList []any

NumberList is a dynamic array whose numeric leaves retain exact JSON Numbers.

func (*NumberList) UnmarshalJSON

func (m *NumberList) UnmarshalJSON(raw []byte) error

type NumberMap

type NumberMap map[string]any

NumberMap is a dynamic object whose numeric leaves retain exact JSON Numbers.

func (*NumberMap) UnmarshalJSON

func (m *NumberMap) UnmarshalJSON(raw []byte) error

type RawMessage

type RawMessage []byte

RawMessage stores standard JSON even when invoked from transient projected typed binding. It never exposes internal raw WTF8 as persisted or wire JSON.

func (RawMessage) MarshalJSON

func (r RawMessage) MarshalJSON() ([]byte, error)

func (*RawMessage) UnmarshalJSON

func (r *RawMessage) UnmarshalJSON(raw []byte) error

type TokenReader

type TokenReader struct {
	*Decoder
	// contains filtered or unexported fields
}

TokenReader retains a caller-owned complete buffer for lossless ordered token traversal. Its embedded Decoder shares the same framing and typed binding.

func NewTokenReader

func NewTokenReader(raw []byte) *TokenReader

func (*TokenReader) More

func (d *TokenReader) More() bool

func (*TokenReader) Token

func (d *TokenReader) Token() (any, error)

Jump to

Keyboard shortcuts

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