Documentation
¶
Index ¶
- Variables
- type Type
- type Value
- func (v *Value) AsArray() ([]*Value, error)
- func (v *Value) AsBoolean() (bool, error)
- func (v *Value) AsInteger() (int64, error)
- func (v *Value) AsNull() (struct{}, error)
- func (v *Value) AsNumber() (float64, error)
- func (v *Value) AsObject() (map[string]*Value, error)
- func (v *Value) AsString() (string, error)
- func (v *Value) Index(i int) *Value
- func (v *Value) Key(k string) *Value
- func (v *Value) String() string
- func (v *Value) Type() Type
Constants ¶
This section is empty.
Variables ¶
var ( // A value is trying to be cast to an incorrect type. ErrType = errors.New("type error") // A problem occured while parsing the JSON ErrParse = errors.New("parse error") )
Functions ¶
This section is empty.
Types ¶
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
A structured JSON value
func Parse ¶
Parses a JSON value from a Reader. If it cannot read a valid value, it returns an error. Returns nil error otherwise.
func ParseBytes ¶
Parses a JSON value from a byte slice. If it cannot read a valid value, it returns an error. Returns nil error otherwise.
func ParseString ¶
Parses a JSON value from a string. If it cannot read a valid value, it returns an error. Returns nil error otherwise.
func (*Value) AsArray ¶
Extracts an array value from the JSON. Returns ErrType if the value is not array, nil otherwise.
func (*Value) AsBoolean ¶
Extracts a boolean value from the JSON. Returns ErrType if the value is not boolean, nil otherwise.
func (*Value) AsInteger ¶
Extracts an integer from the JSON. Will not convert decimal to integer. If decimal precision is needed, use AsNumber instead. Returns ErrType if the value is niether a number nor an integer. Returns nil otherwise.
func (*Value) AsNull ¶
Extracts a null value from the JSON. Returns ErrType if the value is not null, nil otherwise.
func (*Value) AsNumber ¶
Extracts a number from the JSON. If the value is an integer, it is cast to a float64. If integer precision is needed, use AsInteger instead. Returns ErrType if the value is niether a number nor an integer. Returns nil otherwise.
func (*Value) AsObject ¶
Extracts an object value from the JSON. Returns ErrType if the value is not object, nil otherwise.
func (*Value) AsString ¶
Extracts a string value from the JSON. Returns ErrType if the value is not string, nil otherwise.
func (*Value) Index ¶ added in v1.1.0
Fluent inteface for accessing array members. Returns nil instead of error.
func (*Value) Key ¶ added in v1.1.0
Fluent inteface for accessing object members. Returns nil instead of error.