json

package
v0.0.0-...-15711b3 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2019 License: MIT, MIT Imports: 11 Imported by: 0

Documentation

Overview

Package implementing the JSON -- http://json.org/ -- spec.

The `json.Marshal` and `json.Unmarshal` functions are the quickest way to convert your Go objects to and from serial JSON.

The `json.NewMarshaller` and `json.NewUmarshaller` functions give a little more control. If performance is important, prefer these; recycling the marshaller instances will significantly cut down on memory allocations and improve performance.

The `*Atlased` variants of constructors allow you set up marshalling with an `refmt/obj/atlas.Atlas`, unlocking all of refmt's advanced features and custom object mapping powertools.

The `json.Encoder` and `json.Decoder` types implement the low-level functionality of converting serial JSON byte streams into refmt Token streams. Users don't usually need to use these directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

func MarshalAtlased

func MarshalAtlased(cfg EncodeOptions, v interface{}, atl atlas.Atlas) ([]byte, error)

func Unmarshal

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

func UnmarshalAtlased

func UnmarshalAtlased(data []byte, v interface{}, atl atlas.Atlas) error

Types

type DecodeOptions

type DecodeOptions struct {
}

func (DecodeOptions) IsDecodeOptions

func (DecodeOptions) IsDecodeOptions()

marker method -- you may use this type to instruct `refmt.Marshal` what kind of encoder to use.

type Decoder

type Decoder struct {
	// contains filtered or unexported fields
}

func NewDecoder

func NewDecoder(r io.Reader) (d *Decoder)

func (*Decoder) Reset

func (d *Decoder) Reset()

func (*Decoder) Step

func (d *Decoder) Step(tokenSlot *Token) (done bool, err error)

type EncodeOptions

type EncodeOptions struct {
	// If set, this will be prefixed to every "line" to pretty-print.
	// (Typically you want to just set this to `[]byte{'\n'}`!)
	Line []byte

	// If set, this will be prefixed $N$ times before each line's content to pretty-print.
	// (Likely values are a tab, or a few spaces.)
	Indent []byte
}

func (EncodeOptions) IsEncodeOptions

func (EncodeOptions) IsEncodeOptions()

marker method -- you may use this type to instruct `refmt.Marshal` what kind of encoder to use.

type Encoder

type Encoder struct {
	// contains filtered or unexported fields
}

A json.Encoder is a TokenSink implementation that emits json bytes.

func NewEncoder

func NewEncoder(wr io.Writer, cfg EncodeOptions) *Encoder

func (*Encoder) Reset

func (d *Encoder) Reset()

func (*Encoder) Step

func (d *Encoder) Step(tok *Token) (done bool, err error)

type Marshaller

type Marshaller struct {
	// contains filtered or unexported fields
}

func NewMarshaller

func NewMarshaller(wr io.Writer) *Marshaller

func NewMarshallerAtlased

func NewMarshallerAtlased(wr io.Writer, cfg EncodeOptions, atl atlas.Atlas) *Marshaller

func (*Marshaller) Marshal

func (x *Marshaller) Marshal(v interface{}) error

type Unmarshaller

type Unmarshaller struct {
	// contains filtered or unexported fields
}

func NewUnmarshaller

func NewUnmarshaller(r io.Reader) *Unmarshaller

func NewUnmarshallerAtlased

func NewUnmarshallerAtlased(r io.Reader, atl atlas.Atlas) *Unmarshaller

func (*Unmarshaller) Unmarshal

func (x *Unmarshaller) Unmarshal(v interface{}) error

Jump to

Keyboard shortcuts

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