Documentation
¶
Index ¶
- func DecodeAny[T any](d Decoder) (T, error)
- func DecodeArray[T any](parseFn func(d Decoder) (T, error)) func(d Decoder) ([]T, error)
- func DecodeBool(d Decoder) (bool, error)
- func DecodeBoolPtr(d Decoder) (*bool, error)
- func DecodeBytes(d Decoder) ([]byte, error)
- func DecodeFloat[T ~float32 | ~float64](d Decoder) (T, error)
- func DecodeFloatPtr[T ~float32 | ~float64](d Decoder) (*T, error)
- func DecodeInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (T, error)
- func DecodeIntKey[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (T, error)
- func DecodeIntPtr[T ~int | ~int8 | ~int16 | ~int32 | ~int64](d Decoder) (*T, error)
- 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)
- func DecodeObject[T Object](newFn func() T) func(d Decoder) (T, error)
- func DecodeObjectBegin(d Decoder) error
- func DecodeObjectEnd(d Decoder) error
- func DecodeString(d Decoder) (string, error)
- func DecodeStringPtr(d Decoder) (*string, error)
- func DecodeUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (T, error)
- func DecodeUintKey[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (T, error)
- func DecodeUintPtr[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](d Decoder) (*T, error)
- func DecodeValue[T any](parseFn func(string, json.Kind) (T, error), errFormat string) func(d Decoder) (T, error)
- func DecodeValuePtr[T any](parseFn func(string, json.Kind) (T, error), errFormat string) func(d Decoder) (*T, error)
- func EncodeInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](e Encoder, i T) error
- func Marshal(i any, opts ...MarshalOptions) ([]byte, error)
- func MarshalIndent(i any, prefix, indent string) ([]byte, error)
- func MarshalWrite(w io.Writer, i any, opts ...MarshalOptions) error
- func NewDecoder(r io.Reader) json.Decoder
- func NewEncoder(w io.Writer) json.Encoder
- func ParseBool(token string, k json.Kind) (bool, error)
- func ParseBytes(token string, k json.Kind) ([]byte, error)
- func ParseFloat[T ~float32 | ~float64](token string, k json.Kind) (T, error)
- func ParseInt[T ~int | ~int8 | ~int16 | ~int32 | ~int64](token string, k json.Kind) (T, error)
- func ParseIntKey[T ~int | ~int8 | ~int16 | ~int32 | ~int64](token string, _ json.Kind) (T, error)
- func ParseString(token string, k json.Kind) (string, error)
- func ParseUint[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](token string, k json.Kind) (T, error)
- func ParseUintKey[T ~uint | ~uint8 | ~uint16 | ~uint32 | ~uint64](token string, _ json.Kind) (T, error)
- func Unmarshal(b []byte, i any) error
- func UnmarshalRead(r io.Reader, i any) error
- type Decoder
- type Deterministic
- type Encoder
- type Indent
- type IndentPrefix
- type MarshalOptions
- type NilMapAsNull
- type NilSliceAsNull
- type NotForPublicUse
- type Object
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DecodeAny ¶
DecodeAny decodes the next JSON value (scalar, object, or array) into a Go value using Decoder.Unmarshal.
func DecodeArray ¶
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 ¶
DecodeBool reads the next JSON value from the decoder and parses it as bool.
func DecodeBoolPtr ¶
DecodeBoolPtr reads the next JSON value and parses it as *bool. Returns nil if the JSON token is null.
func DecodeBytes ¶
DecodeBytes reads the next JSON value and parses it as base64-decoded bytes.
func DecodeFloat ¶
DecodeFloat reads the next JSON value and parses it as a float type T.
func DecodeFloatPtr ¶
DecodeFloatPtr reads the next JSON value and parses it into a pointer to float type T.
func DecodeIntKey ¶
DecodeIntKey reads a JSON object key and parses it as an integer type T.
func DecodeIntPtr ¶
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 ¶
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 ¶
DecodeObjectBegin consumes the opening '{' token of a JSON object. Returns an error if the next token is not '{'.
func DecodeObjectEnd ¶
DecodeObjectEnd consumes the closing '}' token of a JSON object. Returns an error if the next token is not '}'.
func DecodeString ¶
DecodeString reads the next JSON value and parses it as a string.
func DecodeStringPtr ¶
DecodeStringPtr reads the next JSON value and parses it as a pointer to string.
func DecodeUint ¶
DecodeUint reads the next JSON value and parses it as an unsigned integer type T.
func DecodeUintKey ¶
DecodeUintKey reads a JSON object key and parses it as an unsigned integer type T.
func DecodeUintPtr ¶
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 Marshal ¶
func Marshal(i any, opts ...MarshalOptions) ([]byte, error)
Marshal marshals a Go value into JSON bytes.
func MarshalIndent ¶
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 ¶
NewDecoder creates a new jsonv2.Decoder that implements the json.Decoder interface.
func NewEncoder ¶
NewEncoder creates a new jsonv2.Encoder that implements the json.Encoder interface.
func ParseBool ¶
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 ¶
ParseBytes parses a JSON string token as base64-encoded bytes.
func ParseFloat ¶
ParseFloat parses a JSON number token into a float type T.
func ParseInt ¶
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 ¶
ParseIntKey parses a JSON object key as an integer type T. Returns an error if parsing fails or the value overflows.
func ParseString ¶
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.
Types ¶
type Deterministic ¶
type Deterministic bool
func (Deterministic) JSONOptions ¶
func (Deterministic) JSONOptions(NotForPublicUse)
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.