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 ¶
- func AppendJSON(out []byte, x interface{}) ([]byte, error)
- func Marshal(x interface{}) ([]byte, error)
- func Unmarshal(data []byte, x interface{}) error
- func UnmarshalFromNode(n njson.Node, x interface{}) error
- func UnmarshalFromString(s string, x interface{}) (err error)
- type Cache
- type Decoder
- type Encoder
- type LineDecoder
- type LineEncoder
- type Omiter
- type Options
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendJSON ¶ added in v0.0.10
AppendJSON appends the JSON encoding of a value to a buffer
func Unmarshal ¶
Unmarshal behaves like json.Unmarshal. It copies the data to string. To avoid allocations use UnmarshalFromString or UnmarshalFromNode
func UnmarshalFromNode ¶
UnmarshalFromNode unmarshals from an njson.Node
func UnmarshalFromString ¶
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
type Decoder ¶
type Decoder interface {
Decode(x interface{}, n njson.Node) error
// contains filtered or unexported methods
}
Decoder is a type specific decoder
type Encoder ¶
type Encoder interface {
Encode(out []byte, x interface{}) ([]byte, error)
// contains filtered or unexported methods
}
Encoder is a type specific encoder
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 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