json

package
v1.2.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2018 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package json implements encoding and decoding of JSON.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

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

Marshal returns the JSON encoding of v.

func Unmarshal

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

Unmarshal parses the JSON-encoded data and stores the result in the value pointed to by v.

Types

type Boolean

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

func (Boolean) Bool

func (v Boolean) Bool() bool

func (Boolean) MarshalJSON

func (v Boolean) MarshalJSON() ([]byte, error)

func (*Boolean) UnmarshalJSON

func (v *Boolean) UnmarshalJSON(b []byte) error

type Decoder

type Decoder struct {
	*json.Decoder
}

A Decoder reads and decodes JSON values from an input stream.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder returns a new decoder that reads from r.

type Encoder

type Encoder struct {
	*json.Encoder
}

An Encoder writes JSON values to an output stream.

func NewEncoder

func NewEncoder(w io.Writer) *Encoder

NewEncoder returns a new encoder that writes to w.

type Node

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

Node is an interface for all JSON nodes.

func NewNode

func NewNode(r io.Reader) *Node

NewNode reads and decodes a JSON from io.Reader then returns a Node of it.

func (*Node) Bytes

func (n *Node) Bytes() []byte

Bytes returns the raw JSON string in []byte.

func (*Node) Error

func (n *Node) Error() error

Error returns the JSON parse error, if any.

func (*Node) Get

func (n *Node) Get(key string) *Node

Get gets object's inner value. Only works with Object value type.

func (*Node) GetN

func (n *Node) GetN(i int) *Node

GetN gets array's inner value. Only works with Array value type. 0 for the first item.

func (*Node) Int

func (n *Node) Int() int

Int unmarshal the JSON into int.

func (*Node) IsArray

func (n *Node) IsArray() bool

IsArray checks whether the node is valid JSON array.

func (*Node) IsBool

func (n *Node) IsBool() bool

IsBool checks whether the node is valid JSON boolean.

func (*Node) IsEmpty

func (n *Node) IsEmpty() bool

IsEmpty checks whether the node is having empty value.

func (*Node) IsNull

func (n *Node) IsNull() bool

IsNull checks whether the node is valid JSON null.

func (*Node) IsNumber

func (n *Node) IsNumber() bool

IsNumber checks whether the node is valid JSON number.

func (*Node) IsObject

func (n *Node) IsObject() bool

IsObject checks whether the node is valid JSON object.

func (*Node) IsString

func (n *Node) IsString() bool

IsString checks whether the node is valid JSON string.

func (*Node) IsValid

func (n *Node) IsValid() bool

IsValid checks whether the node is valid JSON value.

func (*Node) Keys

func (n *Node) Keys() []string

Keys gets an array object's keys, or nil if not an object.

func (*Node) Len

func (n *Node) Len() int

Len gets the length of the value. Only works with Array and String value type.

func (*Node) SortedKeys

func (n *Node) SortedKeys() []string

SortedKeys gets an array object's keys in alphabetical order

func (*Node) String

func (n *Node) String() string

String unmarshal the JSON into string.

func (*Node) Type

func (n *Node) Type() lzjson.Type

Type returns the lzjson.Type of the containing JSON value.

func (*Node) Unmarshal

func (n *Node) Unmarshal(v interface{}) error

Unmarshal parses the JSON node data into variable v.

type Timestamp

type Timestamp struct {
	time.Time
}

func (*Timestamp) MarshalJSON

func (t *Timestamp) MarshalJSON() ([]byte, error)

func (*Timestamp) UnmarshalJSON

func (t *Timestamp) UnmarshalJSON(b []byte) error

Jump to

Keyboard shortcuts

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