jsonline

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package jsonline decodes and encodes the JSON objects of a native session log so that an object read and written again is the same JSON value: members the Go type does not declare are kept, and a declared member that was absent stays absent, a null stays null. The format packages embed Members in every type they decode. It imports the standard library alone, as the format packages must.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data []byte, v any, m *Members) error

Decode unmarshals data into v, a pointer to a struct type without its own UnmarshalJSON, and fills m from the members data carries.

func DecodeLenient

func DecodeLenient(data []byte, v any, m *Members) error

DecodeLenient is Decode for a type that is a union of several shapes, where one shape's member may share a name with another's of a different JSON type: when the object does not decode whole, each declared member is decoded alone, and one whose value does not fit its field is kept in Extra, written back as it was, and listed by Members.Mistyped. It fails only when data is not a JSON object.

func Encode

func Encode(v any, m *Members) ([]byte, error)

Encode marshals v, a struct value of a type without its own MarshalJSON, as m says: a decoded object writes back the declared members its input carried, null where they were null, and an object built in Go writes its non-zero members. Extra is written beside them.

Types

type Members

type Members struct {
	// Extra holds the members the type does not declare, verbatim.
	Extra map[string]json.RawMessage `json:"-"`
	// contains filtered or unexported fields
}

Members is embedded in every object a format package decodes. It keeps the members the Go type does not declare, and remembers which declared members the input carried and which were null, so an object decoded and encoded again is the same JSON value: a member absent from the input stays absent, an explicit false or zero stays, and a null stays null.

func (*Members) Has

func (m *Members) Has(name string) bool

Has reports whether the input carried the declared member name, null or not. An object built in Go rather than decoded reports false.

func (*Members) IsNull

func (m *Members) IsNull(name string) bool

IsNull reports whether the input carried name as null.

func (*Members) Mistyped

func (m *Members) Mistyped() []string

Mistyped lists the declared members DecodeLenient found holding a value of another JSON type, which it kept in Extra instead, sorted.

Jump to

Keyboard shortcuts

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