unjson

package
v0.0.12 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

Package unjson uses reflection to marshal/unmarshal JSON from njson.Node input It's NOT a 'drop-in' replacement for "encoding/json".

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendJSON added in v0.0.10

func AppendJSON(out []byte, x interface{}) ([]byte, error)

AppendJSON appends the JSON encoding of a value to a buffer

func Marshal

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

Marshal behaves like json.Marshal To avoid allocations use AppendJSON

func Unmarshal

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

Unmarshal behaves like json.Unmarshal. It copies the data to string. To avoid allocations use UnmarshalFromString or UnmarshalFromNode

func UnmarshalFromNode

func UnmarshalFromNode(n njson.Node, x interface{}) error

UnmarshalFromNode unmarshals from an njson.Node

func UnmarshalFromString

func UnmarshalFromString(s string, x interface{}) (err error)

UnmarshalFromString unmarshals from a JSON string

Types

type Cache added in v0.0.11

type Cache struct {
	Options
	// contains filtered or unexported fields
}

Cache is an Encoder/Decoder cache for specific options

func (*Cache) Decoder added in v0.0.11

func (c *Cache) Decoder(typ reflect.Type) (dec Decoder, err error)

Decoder returns a Decoder for the type using the tag key from cache.Options

func (*Cache) Encoder added in v0.0.11

func (c *Cache) Encoder(typ reflect.Type) (enc Encoder, err error)

Encoder returns an Encoder for the type using cache.Options

type Decoder

type Decoder interface {
	Decode(x interface{}, n njson.Node) error
	// contains filtered or unexported methods
}

Decoder is a type specific decoder

func NewTypeDecoder added in v0.0.11

func NewTypeDecoder(typ reflect.Type, tag string) (Decoder, error)

NewTypeDecoder creates a new decoder for a type.

type Encoder

type Encoder interface {
	Encode(out []byte, x interface{}) ([]byte, error)
	// contains filtered or unexported methods
}

Encoder is a type specific encoder

func NewTypeEncoder added in v0.0.11

func NewTypeEncoder(typ reflect.Type, options Options) (Encoder, error)

NewTypeEncoder creates a new Encoder for a reflect.Type

type LineDecoder

type LineDecoder struct {
	Decoder // Use a specific type decoder
	// contains filtered or unexported fields
}

LineDecoder decodes from a newline delimited JSON stream. (http://ndjson.org/)

func NewLineDecoder

func NewLineDecoder(r io.Reader) *LineDecoder

NewLineDecoder creates a new LineDecoder

func (*LineDecoder) Decode

func (d *LineDecoder) Decode(x interface{}) (err error)

Decode decodes the next JSON line in the stream to x

type LineEncoder

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

LineEncoder encodes to a newline delimited JSON stream. (http://ndjson.org/)

func NewLineEncoder

func NewLineEncoder(w io.Writer) *LineEncoder

NewLineEncoder creates a new LineEncoder

func (*LineEncoder) Encode

func (e *LineEncoder) Encode(x interface{}) (err error)

Encode encodes a value to a new JSON line on the stream.

type Omiter

type Omiter interface {
	Omit() bool
}

Omiter implements custom omitempty logic

type Options

type Options struct {
	Tag        string
	OmitEmpty  bool   // Force omitempty on all fields
	OmitMethod string // Method name for checking if a value is empty defaults to 'Omit'
	AllowNaN   bool   // Allow NaN values for numbers
	AllowInf   bool   // Allow ±Inf values for numbers
}

Options holds options for an Encoder/Decoder

func DefaultOptions

func DefaultOptions() Options

DefaultOptions returns the default options for an Encoder/Decoder

Jump to

Keyboard shortcuts

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