json

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 2024 License: Apache-2.0 Imports: 12 Imported by: 316 modules, 290 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 json contains helper functions for encoding and decoding JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeDate

func DecodeDate(d *jx.Decoder) (v time.Time, err error)

DecodeDate decodes date from json.

func DecodeDateTime

func DecodeDateTime(d *jx.Decoder) (v time.Time, err error)

DecodeDateTime decodes date-time from json.

func DecodeDuration

func DecodeDuration(d *jx.Decoder) (v time.Duration, err error)

DecodeDuration decodes duration from json.

func DecodeIP

func DecodeIP(d *jx.Decoder) (netip.Addr, error)

DecodeIP decodes netip.Addr.

func DecodeIPv4 added in v0.55.0

func DecodeIPv4(d *jx.Decoder) (netip.Addr, error)

DecodeIPv4 decodes netip.Addr.

func DecodeIPv6 added in v0.55.0

func DecodeIPv6(d *jx.Decoder) (netip.Addr, error)

DecodeIPv6 decodes netip.Addr.

func DecodeMAC added in v0.82.0

func DecodeMAC(d *jx.Decoder) (net.HardwareAddr, error)

DecodeMAC decodes net.HardwareAddr.

func DecodeStringFloat32 added in v0.70.0

func DecodeStringFloat32(d *jx.Decoder) (float32, error)

DecodeStringFloat32 decodes string float32 from json.

func DecodeStringFloat64 added in v0.70.0

func DecodeStringFloat64(d *jx.Decoder) (float64, error)

DecodeStringFloat64 decodes string float64 from json.

func DecodeStringInt added in v0.70.0

func DecodeStringInt(d *jx.Decoder) (int, error)

DecodeStringInt decodes string int from json.

func DecodeStringInt8 added in v0.70.0

func DecodeStringInt8(d *jx.Decoder) (int8, error)

DecodeStringInt8 decodes string int8 from json.

func DecodeStringInt16 added in v0.70.0

func DecodeStringInt16(d *jx.Decoder) (int16, error)

DecodeStringInt16 decodes string int16 from json.

func DecodeStringInt32 added in v0.29.0

func DecodeStringInt32(d *jx.Decoder) (int32, error)

DecodeStringInt32 decodes string int32 from json.

func DecodeStringInt64 added in v0.29.0

func DecodeStringInt64(d *jx.Decoder) (int64, error)

DecodeStringInt64 decodes string int64 from json.

func DecodeStringUint added in v0.70.0

func DecodeStringUint(d *jx.Decoder) (uint, error)

DecodeStringUint decodes string int from json.

func DecodeStringUint8 added in v0.70.0

func DecodeStringUint8(d *jx.Decoder) (uint8, error)

DecodeStringUint8 decodes string int8 from json.

func DecodeStringUint16 added in v0.70.0

func DecodeStringUint16(d *jx.Decoder) (uint16, error)

DecodeStringUint16 decodes string int16 from json.

func DecodeStringUint32 added in v0.70.0

func DecodeStringUint32(d *jx.Decoder) (uint32, error)

DecodeStringUint32 decodes string int32 from json.

func DecodeStringUint64 added in v0.70.0

func DecodeStringUint64(d *jx.Decoder) (uint64, error)

DecodeStringUint64 decodes string int64 from json.

func DecodeStringUnixMicro added in v0.46.1

func DecodeStringUnixMicro(d *jx.Decoder) (time.Time, error)

DecodeStringUnixMicro decodes unix-micro from json string.

func DecodeStringUnixMilli added in v0.46.1

func DecodeStringUnixMilli(d *jx.Decoder) (time.Time, error)

DecodeStringUnixMilli decodes unix-milli from json string.

func DecodeStringUnixNano added in v0.46.1

func DecodeStringUnixNano(d *jx.Decoder) (time.Time, error)

DecodeStringUnixNano decodes unix-nano from json string.

func DecodeStringUnixSeconds added in v0.46.1

func DecodeStringUnixSeconds(d *jx.Decoder) (time.Time, error)

DecodeStringUnixSeconds decodes unix-seconds from json string.

func DecodeTime

func DecodeTime(d *jx.Decoder) (v time.Time, err error)

DecodeTime decodes time from json.

func DecodeTimeFormat added in v1.6.0

func DecodeTimeFormat(d *jx.Decoder, layout string) (v time.Time, err error)

DecodeTimeFormat decodes date, time & date-time from json using a custom layout.

func DecodeURI

func DecodeURI(i *jx.Decoder) (v url.URL, err error)

DecodeURI decodes url.URL from json.

func DecodeUUID

func DecodeUUID(i *jx.Decoder) (v uuid.UUID, err error)

DecodeUUID decodes UUID from json.

func DecodeUnixMicro added in v0.30.0

func DecodeUnixMicro(d *jx.Decoder) (time.Time, error)

DecodeUnixMicro decodes unix-micro from json string.

func DecodeUnixMilli added in v0.30.0

func DecodeUnixMilli(d *jx.Decoder) (time.Time, error)

DecodeUnixMilli decodes unix-milli from json string.

func DecodeUnixNano added in v0.30.0

func DecodeUnixNano(d *jx.Decoder) (time.Time, error)

DecodeUnixNano decodes unix-nano from json string.

func DecodeUnixSeconds added in v0.30.0

func DecodeUnixSeconds(d *jx.Decoder) (time.Time, error)

DecodeUnixSeconds decodes unix-seconds from json string.

func Encode

func Encode(m Marshaler) []byte

Encode Marshaler to byte slice.

func EncodeDate

func EncodeDate(e *jx.Encoder, v time.Time)

EncodeDate encodes date to json.

func EncodeDateTime

func EncodeDateTime(e *jx.Encoder, v time.Time)

EncodeDateTime encodes date-time to json.

func EncodeDuration

func EncodeDuration(e *jx.Encoder, v time.Duration)

EncodeDuration encodes duration to json.

func EncodeIP

func EncodeIP(s *jx.Encoder, v netip.Addr)

EncodeIP encodes netip.Addr.

func EncodeIPv4 added in v0.55.0

func EncodeIPv4(s *jx.Encoder, v netip.Addr)

EncodeIPv4 encodes netip.Addr.

func EncodeIPv6 added in v0.55.0

func EncodeIPv6(s *jx.Encoder, v netip.Addr)

EncodeIPv6 encodes netip.Addr.

func EncodeMAC added in v0.82.0

func EncodeMAC(e *jx.Encoder, v net.HardwareAddr)

EncodeMAC encodes net.HardwareAddr.

func EncodeStringFloat32 added in v0.70.0

func EncodeStringFloat32(e *jx.Encoder, v float32)

EncodeStringFloat32 encodes string float32 to json.

func EncodeStringFloat64 added in v0.70.0

func EncodeStringFloat64(e *jx.Encoder, v float64)

EncodeStringFloat64 encodes string float64 to json.

func EncodeStringInt added in v0.70.0

func EncodeStringInt(e *jx.Encoder, v int)

EncodeStringInt encodes string int to json.

func EncodeStringInt8 added in v0.70.0

func EncodeStringInt8(e *jx.Encoder, v int8)

EncodeStringInt8 encodes string int8 to json.

func EncodeStringInt16 added in v0.70.0

func EncodeStringInt16(e *jx.Encoder, v int16)

EncodeStringInt16 encodes string int16 to json.

func EncodeStringInt32 added in v0.29.0

func EncodeStringInt32(e *jx.Encoder, v int32)

EncodeStringInt32 encodes string int32 to json.

func EncodeStringInt64 added in v0.29.0

func EncodeStringInt64(e *jx.Encoder, v int64)

EncodeStringInt64 encodes string int64 to json.

func EncodeStringUint added in v0.70.0

func EncodeStringUint(e *jx.Encoder, v uint)

EncodeStringUint encodes string uint to json.

func EncodeStringUint8 added in v0.70.0

func EncodeStringUint8(e *jx.Encoder, v uint8)

EncodeStringUint8 encodes string uint8 to json.

func EncodeStringUint16 added in v0.70.0

func EncodeStringUint16(e *jx.Encoder, v uint16)

EncodeStringUint16 encodes string uint16 to json.

func EncodeStringUint32 added in v0.70.0

func EncodeStringUint32(e *jx.Encoder, v uint32)

EncodeStringUint32 encodes string uint32 to json.

func EncodeStringUint64 added in v0.70.0

func EncodeStringUint64(e *jx.Encoder, v uint64)

EncodeStringUint64 encodes string uint64 to json.

func EncodeStringUnixMicro added in v0.46.1

func EncodeStringUnixMicro(e *jx.Encoder, v time.Time)

EncodeStringUnixMicro encodes unix-micro to json string.

func EncodeStringUnixMilli added in v0.46.1

func EncodeStringUnixMilli(e *jx.Encoder, v time.Time)

EncodeStringUnixMilli encodes unix-milli to json string.

func EncodeStringUnixNano added in v0.46.1

func EncodeStringUnixNano(e *jx.Encoder, v time.Time)

EncodeStringUnixNano encodes unix-nano to json string.

func EncodeStringUnixSeconds added in v0.46.1

func EncodeStringUnixSeconds(e *jx.Encoder, v time.Time)

EncodeStringUnixSeconds encodes unix-seconds to json string.

func EncodeTime

func EncodeTime(e *jx.Encoder, v time.Time)

EncodeTime encodes time to json.

func EncodeTimeFormat added in v1.6.0

func EncodeTimeFormat(e *jx.Encoder, v time.Time, layout string)

EncodeTimeFormat encodes date, time & date-time to json using a custom layout.

func EncodeURI

func EncodeURI(s *jx.Encoder, v url.URL)

EncodeURI encodes url.URL to json.

func EncodeUUID

func EncodeUUID(s *jx.Encoder, v uuid.UUID)

EncodeUUID encodes UUID to json.

func EncodeUnixMicro added in v0.30.0

func EncodeUnixMicro(e *jx.Encoder, v time.Time)

EncodeUnixMicro encodes unix-micro to json string.

func EncodeUnixMilli added in v0.30.0

func EncodeUnixMilli(e *jx.Encoder, v time.Time)

EncodeUnixMilli encodes unix-milli to json string.

func EncodeUnixNano added in v0.30.0

func EncodeUnixNano(e *jx.Encoder, v time.Time)

EncodeUnixNano encodes unix-nano to json string.

func EncodeUnixSeconds added in v0.30.0

func EncodeUnixSeconds(e *jx.Encoder, v time.Time)

EncodeUnixSeconds encodes unix-seconds to json string.

func Equal added in v0.34.0

func Equal(a, b []byte) (bool, error)

Equal compares two JSON values.

func Marshal

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

Marshal value to json.

func NewTimeDecoder added in v1.6.0

func NewTimeDecoder(layout string) func(i *jx.Decoder) (time.Time, error)

NewTimeDecoder returns a new time decoder using a custom layout.

func NewTimeEncoder added in v1.6.0

func NewTimeEncoder(layout string) func(e *jx.Encoder, v time.Time)

NewTimeEncoder returns a new time encoder using a custom layout.

func Unmarshal

func Unmarshal(data []byte, val any) error

Unmarshal value from json.

Types

type Marshaler

type Marshaler interface {
	Encode(e *jx.Encoder)
}

Marshaler implements json writing.

type Nullable

type Nullable interface {
	IsNil() bool
}

Nullable can be nil (but defined) or not.

type Resettable

type Resettable interface {
	Reset()
}

Resettable value can be unset.

type Settable

type Settable interface {
	IsSet() bool
}

Settable value can be set (present) or unset (i.e. not provided or undefined).

type Unmarshaler

type Unmarshaler interface {
	Decode(d *jx.Decoder) error
}

Unmarshaler implements json reading.

type Value

type Value interface {
	Marshaler
	Unmarshaler
}

Value represents a json value.

Jump to

Keyboard shortcuts

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