Documentation ¶
Overview ¶
copied (almost) entirely from the Go standard library, encoding/json/decode.go
Index ¶
- Constants
- type Decoder
- type JSON
- func (j *JSON) Array(args ...[]interface{}) []*JSON
- func (j *JSON) Bool(args ...bool) bool
- func (j *JSON) Float64(args ...float64) float64
- func (j *JSON) Get(key string) *JSON
- func (j *JSON) Int64(args ...int64) int64
- func (j *JSON) Interface() interface{}
- func (j *JSON) Map(args ...map[string]interface{}) map[string]interface{}
- func (j *JSON) MaybeArray() ([]*JSON, error)
- func (j *JSON) MaybeBool() (bool, error)
- func (j *JSON) MaybeFloat64() (float64, error)
- func (j *JSON) MaybeInt64() (int64, error)
- func (j *JSON) MaybeMap() (map[string]interface{}, error)
- func (j *JSON) MaybeString() (string, error)
- func (j *JSON) String(args ...string) string
- type ObjectStore
Constants ¶
const ( JT_NULL = iota JT_TRUE JT_FALSE JT_NUMERIC JT_UTF8 JT_ARRAY JT_OBJECT JT_INVALID )
const ( SS_NORMAL = iota SS_ESC )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
func NewDecoder ¶
func NewDecoder(store ObjectStore, data []byte) *Decoder
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
func NewFromBytes ¶
func (*JSON) Array ¶
Array guarantees the return of an `[]*JSON` (with optional default)
useful when you explicitly want an `bool` in a single value return context:
myFunc(js.Get("param1").Array(), js.Get("optional_param").Array([]interface{}{"string", 1, 1.1, false}))
func (*JSON) Bool ¶
Bool guarantees the return of an `bool` (with optional default)
useful when you explicitly want an `bool` in a single value return context:
myFunc(js.Get("param1").Bool(), js.Get("optional_param").Bool(true))
func (*JSON) Float64 ¶
Float64 guarantees the return of an `float64` (with optional default)
useful when you explicitly want an `float64` in a single value return context:
myFunc(js.Get("param1").Float64(), js.Get("optional_param").Float64(51.15))
func (*JSON) Get ¶
Get returns a pointer to a new `Json` object for `key` in its `map` representation
useful for chaining operations (to traverse a nested JSON):
js.Get("top_level").Get("dict").Get("value").Int()
func (*JSON) Int64 ¶
Int64 guarantees the return of an `int64` (with optional default)
useful when you explicitly want an `int64` in a single value return context:
myFunc(js.Get("param1").Int64(), js.Get("optional_param").Int64(5150))
func (*JSON) Map ¶
Map guarantees the return of a `map[string]interface{}` (with optional default)
useful when you want to interate over map values in a succinct manner:
for k, v := range js.Get("dictionary").Map() { fmt.Println(k, v) }
func (*JSON) MaybeArray ¶
MaybeArray type asserts to `*[]interface{}`
func (*JSON) MaybeFloat64 ¶
MaybeFloat64 type asserts and parses an `float64`
func (*JSON) MaybeInt64 ¶
MaybeInt64 type asserts and parses an `int64`
func (*JSON) MaybeString ¶
MaybeString type asserts to `string`
type ObjectStore ¶
type ObjectStore interface { NewObject() (interface{}, error) NewArray() (interface{}, error) ObjectAddKey(interface{}, interface{}, interface{}) error ArrayAddItem(interface{}, interface{}) error NewString([]byte) (interface{}, error) NewNumeric([]byte) (interface{}, error) NewTrue() (interface{}, error) NewFalse() (interface{}, error) NewNull() (interface{}, error) }