unjson

package
v0.0.9 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2018 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 Marshal

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

func MarshalTo

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

func Unmarshal

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

func UnmarshalFromNode

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

func UnmarshalFromString

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

Types

type Decoder

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

Decoder is a type specific decoder

func TypeDecoder

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

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

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

type FieldParser

type FieldParser interface {
	// contains filtered or unexported methods
}

func NewFieldParser

func NewFieldParser(key string, omitempty bool) FieldParser

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
}

type Options

type Options struct {
	Tag       string
	OmitEmpty bool
	// FieldParser           // If nil DefaultFieldParser is used
	OmitMethod string // Method name for checking if a value is empty
	HTML       bool   // Escape HTML-safe
	AllowNaN   bool   // Allow NaN values for numbers
	AllowInf   bool   // Allow ±Inf values for numbers
}

func DefaultOptions

func DefaultOptions() Options

type RawString

type RawString string

func (RawString) AppendJSON

func (raw RawString) AppendJSON(dst []byte) ([]byte, error)

func (RawString) String

func (raw RawString) String() string

func (*RawString) UnmarshalFromNode

func (raw *RawString) UnmarshalFromNode(n njson.Node) error

Jump to

Keyboard shortcuts

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