Documentation ¶
Index ¶
- Constants
- Variables
- func Parse(data []byte) (v interface{}, e error)
- func Stringify(v interface{}) (buf []byte, e error)
- 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) 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) MaybeMap() (map[string]interface{}, error)
- func (j *JSON) MaybeString() (string, error)
- func (j *JSON) String(args ...string) string
- type ObjectStore
- type Option
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 ¶
var (
ErrIndexExceededMaximumLength = errors.New("index exceeded maximum length of j.data")
)
Functions ¶
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 { Error error // contains filtered or unexported fields }
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) 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) 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) }