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 ¶
- func AppendString(buf []byte, s string) []byte
- func Marshal(value any) ([]byte, error)
- func Unmarshal(raw []byte, out any, stages ...DecodeStage) error
- func UnmarshalValue(raw []byte) (any, error)
- type DecodeStage
- type Decoder
- type Encoder
- type NumberDecoder
- type NumberList
- type NumberMap
- type RawMessage
- type TokenReader
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendString ¶
AppendString appends one JSON string without HTML escaping, preserving exact UTF16 units and retaining allocation-free appends when capacity permits.
func Marshal ¶
Marshal encodes standard JSON. Existing valid strings retain standard Go JSON escaping; newly admitted lone UTF16 units use their standard \uXXXX spelling.
func UnmarshalValue ¶
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 (*Decoder) DecodeValue ¶
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 ¶
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 (*Encoder) SetEscapeHTML ¶
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 ¶
NumberMap is a dynamic object whose numeric leaves retain exact JSON Numbers.
func (*NumberMap) UnmarshalJSON ¶
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)