json

package
v0.53.0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2022 License: Apache-2.0 Imports: 10 Imported by: 74

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(i *jx.Decoder) (v time.Time, err error)

DecodeDate decodes date from json.

func DecodeDateTime

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

DecodeDateTime decodes date-time from json.

func DecodeDuration

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

DecodeDuration decodes duration from json.

func DecodeIP

func DecodeIP(i *jx.Decoder) (v netip.Addr, err error)

DecodeIP decodes netip.Addr.

func DecodeStringInt32 added in v0.29.0

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

DecodeStringInt32 decodes string int32 from json.

func DecodeStringInt64 added in v0.29.0

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

DecodeStringInt64 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(i *jx.Decoder) (v time.Time, err error)

DecodeTime decodes time from json.

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(s *jx.Encoder, v time.Time)

EncodeDate encodes date to json.

func EncodeDateTime

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

EncodeDateTime encodes date-time to json.

func EncodeDuration

func EncodeDuration(s *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 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 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(s *jx.Encoder, v time.Time)

EncodeTime encodes time to json.

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 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