jsonflow

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2026 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeAny

func DecodeAny[T any](d Decoder) (T, error)

DecodeAny decodes the next JSON value (scalar, object, or array) into a Go value using Decoder.Unmarshal.

func DecodeArray

func DecodeArray[T any](
	parseFn func(d Decoder) (T, error),
) func(d Decoder) ([]T, error)

DecodeArray decodes a JSON array of arbitrary type. parseFn is used to parse each element of the array. Returns nil if the next token is null.

func DecodeBool

func DecodeBool(d Decoder) (bool, error)

DecodeBool reads the next JSON value from the decoder and parses it as bool.

func DecodeBoolPtr

func DecodeBoolPtr(d Decoder) (*bool, error)

DecodeBoolPtr reads the next JSON value and parses it as *bool. Returns nil if the JSON token is null.

func DecodeBytes

func DecodeBytes(d Decoder) ([]byte, error)

DecodeBytes reads the next JSON value and parses it as base64-decoded bytes.

func DecodeFloat

func DecodeFloat[T ~float32 | ~float64](d Decoder) (T, error)

DecodeFloat reads the next JSON value and parses it as a float type T.

func DecodeFloatPtr

func DecodeFloatPtr[T ~float32 | ~float64](d Decoder) (*T, error)

DecodeFloatPtr reads the next JSON value and parses it into a pointer to float type T.

func DecodeInt

func DecodeInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (T, error)

DecodeInt reads the next JSON value and parses it into an integer type T.

func DecodeIntKey

func DecodeIntKey[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (T, error)

DecodeIntKey reads a JSON object key and parses it as an integer type T.

func DecodeIntPtr

func DecodeIntPtr[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (*T, error)

DecodeIntPtr reads the next JSON value and parses it into a pointer to integer type T. Returns nil if the JSON token is null.

func DecodeMap

func DecodeMap[K comparable, V any](
	parseKeyFn func(d Decoder) (K, error),
	parseValFn func(d Decoder) (V, error),
) func(d Decoder) (map[K]V, error)

DecodeMap decodes a JSON object into a Go map. parseKeyFn and parseValFn are used to parse each key and value. Returns nil if the next token is null.

func DecodeObject

func DecodeObject[T Object](
	newFn func() T,
) func(d Decoder) (T, error)

DecodeObject decodes a JSON object into a struct that implements the Object interface. Returns the zero value if the next token is null. Internally calls DecodeJSON on the object to populate its fields.

func DecodeObjectBegin

func DecodeObjectBegin(d Decoder) error

DecodeObjectBegin consumes the opening '{' token of a JSON object. Returns an error if the next token is not '{'.

func DecodeObjectEnd

func DecodeObjectEnd(d Decoder) error

DecodeObjectEnd consumes the closing '}' token of a JSON object. Returns an error if the next token is not '}'.

func DecodeString

func DecodeString(d Decoder) (string, error)

DecodeString reads the next JSON value and parses it as a string.

func DecodeStringPtr

func DecodeStringPtr(d Decoder) (*string, error)

DecodeStringPtr reads the next JSON value and parses it as a pointer to string.

func DecodeUint

func DecodeUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (T, error)

DecodeUint reads the next JSON value and parses it as an unsigned integer type T.

func DecodeUintKey

func DecodeUintKey[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (T, error)

DecodeUintKey reads a JSON object key and parses it as an unsigned integer type T.

func DecodeUintPtr

func DecodeUintPtr[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (*T, error)

DecodeUintPtr reads the next JSON value and parses it into a pointer to unsigned type T.

func DecodeValue

func DecodeValue[T any](
	parseFn func(string, json.Kind) (T, error),
	errFormat string,
) func(d Decoder) (T, error)

DecodeValue parses a scalar JSON value (number, boolean, or string) using parseFn. Returns an error if the next token is null or invalid.

func DecodeValuePtr

func DecodeValuePtr[T any](
	parseFn func(string, json.Kind) (T, error),
	errFormat string,
) func(d Decoder) (*T, error)

DecodeValuePtr parses a scalar JSON value into a pointer type. Returns nil if the next token is null.

func EncodeInt

func EncodeInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](e Encoder, i T) error

EncodeInt encodes an integer value to JSON.

func Marshal

func Marshal(i any, opts ...MarshalOptions) ([]byte, error)

Marshal marshals a Go value into JSON bytes.

func MarshalIndent

func MarshalIndent(i any, prefix, indent string) ([]byte, error)

MarshalIndent marshals a Go value into JSON bytes with indentation.

func MarshalWrite

func MarshalWrite(w io.Writer, i any, opts ...MarshalOptions) error

MarshalWrite marshals a Go value into JSON bytes and writes them to a writer.

func NewDecoder

func NewDecoder(r io.Reader) json.Decoder

NewDecoder creates a new jsonv2.Decoder that implements the json.Decoder interface.

func NewEncoder

func NewEncoder(w io.Writer) json.Encoder

NewEncoder creates a new jsonv2.Encoder that implements the json.Encoder interface.

func ParseBool

func ParseBool(token string, k json.Kind) (bool, error)

ParseBool parses a JSON boolean token into a Go bool. The input Kind must be 't' or 'f', otherwise an error is returned.

func ParseBytes

func ParseBytes(token string, k json.Kind) ([]byte, error)

ParseBytes parses a JSON string token as base64-encoded bytes.

func ParseFloat

func ParseFloat[T ~float32 | ~float64](token string, k json.Kind) (T, error)

ParseFloat parses a JSON number token into a float type T.

func ParseInt

func ParseInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](token string, k json.Kind) (T, error)

ParseInt parses a JSON number token into an integer type T. Returns an error if the token is not a number or if the value overflows.

func ParseIntKey

func ParseIntKey[T ~int | ~int8 | ~int16 | ~int32 | ~int64](token string, _ json.Kind) (T, error)

ParseIntKey parses a JSON object key as an integer type T. Returns an error if parsing fails or the value overflows.

func ParseString

func ParseString(token string, k json.Kind) (string, error)

ParseString parses a JSON string token into a Go string.

func ParseUint

func ParseUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](token string, k json.Kind) (T, error)

ParseUint parses a JSON number token into an unsigned integer type T.

func ParseUintKey

func ParseUintKey[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](token string, _ json.Kind) (T, error)

ParseUintKey parses a JSON object key as an unsigned integer type T.

func Unmarshal

func Unmarshal(b []byte, i any) error

Unmarshal unmarshals JSON bytes into a Go value.

func UnmarshalRead

func UnmarshalRead(r io.Reader, i any) error

UnmarshalRead unmarshals JSON bytes from a reader into a Go value.

Types

type Decoder

type Decoder = json.Decoder

Decoder defines a streaming JSON decoder interface.

type Deterministic

type Deterministic bool

func (Deterministic) JSONOptions

func (Deterministic) JSONOptions(NotForPublicUse)

type Encoder

type Encoder = json.Encoder

Encoder is a streaming JSON encoder.

type Indent

type Indent string

func (Indent) JSONOptions

func (Indent) JSONOptions(NotForPublicUse)

type IndentPrefix

type IndentPrefix string

func (IndentPrefix) JSONOptions

func (IndentPrefix) JSONOptions(NotForPublicUse)

type MarshalOptions

type MarshalOptions interface {
	JSONOptions(NotForPublicUse)
}

MarshalOptions is an interface that defines options for encoding JSON.

type NilMapAsNull

type NilMapAsNull bool

func (NilMapAsNull) JSONOptions

func (NilMapAsNull) JSONOptions(NotForPublicUse)

type NilSliceAsNull

type NilSliceAsNull bool

func (NilSliceAsNull) JSONOptions

func (NilSliceAsNull) JSONOptions(NotForPublicUse)

type NotForPublicUse

type NotForPublicUse struct{}

NotForPublicUse is a private type used to prevent the use of the package outside of this module.

type Object

type Object interface {
	// DecodeJSON reads JSON data from the Decoder and populates the object.
	DecodeJSON(d Decoder) error
}

Object represents a JSON-mappable object that supports streaming decoding.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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