json

package
v3.3.4 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2023 License: ISC Imports: 4 Imported by: 2

Documentation

Overview

Package json allows for different implementations of JSON serializing, as well as extra optional types needed.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DecodeStream

func DecodeStream(r io.Reader, v interface{}) error

DecodeStream uses the default driver.

func EncodeStream

func EncodeStream(w io.Writer, v interface{}) error

EncodeStream uses the default driver.

func Marshal

func Marshal(v interface{}) ([]byte, error)

Marshal uses the default driver.

func PartialUnmarshal added in v3.2.0

func PartialUnmarshal(b []byte, v interface{}) []error

PartialUnmarshal partially unmarshals the JSON in b onto v. Fields that cannot be unmarshaled will be left as their zero values. Fields that can be marshaled will be unmarshaled and its name will be added to the returned slice.

Only use this for the most cursed of JSONs, such as ones coming from Discord. Try not to use this as much as possible.

func Unmarshal

func Unmarshal(data []byte, v interface{}) error

Unmarshal uses the default driver.

Types

type DefaultDriver

type DefaultDriver struct{}

func (DefaultDriver) DecodeStream

func (d DefaultDriver) DecodeStream(r io.Reader, v interface{}) error

func (DefaultDriver) EncodeStream

func (d DefaultDriver) EncodeStream(w io.Writer, v interface{}) error

func (DefaultDriver) Marshal

func (d DefaultDriver) Marshal(v interface{}) ([]byte, error)

func (DefaultDriver) Unmarshal

func (d DefaultDriver) Unmarshal(data []byte, v interface{}) error

type Driver

type Driver interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error

	DecodeStream(r io.Reader, v interface{}) error
	EncodeStream(w io.Writer, v interface{}) error
}
var Default Driver = DefaultDriver{}

Default is the default JSON driver, which uses encoding/json.

type Marshaler

type Marshaler interface {
	MarshalJSON() ([]byte, error)
}

type Raw

type Raw []byte

Raw is a raw encoded JSON value. It implements Marshaler and Unmarshaler and can be used to delay JSON decoding or precompute a JSON encoding. It's taken from encoding/json.

func (Raw) MarshalJSON

func (m Raw) MarshalJSON() ([]byte, error)

Raw returns m as the JSON encoding of m.

func (Raw) String

func (m Raw) String() string

func (*Raw) UnmarshalJSON

func (m *Raw) UnmarshalJSON(data []byte) error

func (Raw) UnmarshalTo

func (m Raw) UnmarshalTo(v interface{}) error

type Unmarshaler

type Unmarshaler interface {
	UnmarshalJSON([]byte) error
}

Directories

Path Synopsis
Package option provides the ability to create omittable primitives.
Package option provides the ability to create omittable primitives.

Jump to

Keyboard shortcuts

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