Documentation
¶
Index ¶
- func Version() string
- type JSON
- func (j *JSON) Array(args ...[]interface{}) []interface{}
- func (j *JSON) Bool(args ...bool) bool
- func (j *JSON) CheckArray() ([]interface{}, bool)
- func (j *JSON) CheckBool() (bool, bool)
- func (j *JSON) CheckFloat64() (float64, bool)
- func (j *JSON) CheckGet(branch ...interface{}) (*JSON, bool)
- func (j *JSON) CheckInt() (int, bool)
- func (j *JSON) CheckInt64() (int64, bool)
- func (j *JSON) CheckJSONArray() ([]*JSON, bool)
- func (j *JSON) CheckJSONMap() (map[string]*JSON, bool)
- func (j *JSON) CheckKeys() ([]string, bool)
- func (j *JSON) CheckMap() (map[string]interface{}, bool)
- func (j *JSON) CheckString() (string, bool)
- func (j *JSON) CheckUint64() (uint64, bool)
- func (j *JSON) Del(key string)
- func (j *JSON) Encode() ([]byte, error)
- func (j *JSON) EncodePretty() ([]byte, error)
- func (j *JSON) Float64(args ...float64) float64
- func (j *JSON) Get(branch ...interface{}) *JSON
- func (j *JSON) Int(args ...int) int
- func (j *JSON) Int64(args ...int64) int64
- func (j *JSON) Interface() interface{}
- func (j *JSON) JSONArray(args ...[]*JSON) []*JSON
- func (j *JSON) JSONMap(args ...map[string]*JSON) map[string]*JSON
- func (j *JSON) Keys() []string
- func (j *JSON) Map(args ...map[string]interface{}) map[string]interface{}
- func (j *JSON) MarshalJSON() ([]byte, error)
- func (j *JSON) Set(key string, val interface{})
- func (j *JSON) SetPath(branch []string, val interface{})
- func (j *JSON) String(args ...string) string
- func (j *JSON) Uint64(args ...uint64) uint64
- func (j *JSON) UnmarshalJSON(p []byte) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSON ¶ added in v0.5.1
type JSON struct {
// contains filtered or unexported fields
}
func NewFromReader ¶ added in v0.5.0
NewFromReader returns a *JSON by decoding from an io.Reader
func NewJSON ¶ added in v0.5.1
NewJson returns a pointer to a new `JSON` object after unmarshaling `body` bytes
func (*JSON) Array ¶ added in v0.5.1
func (j *JSON) Array(args ...[]interface{}) []interface{}
Array guarantees the return of a `[]interface{}` (with optional default)
useful when you want to interate over array values in a succinct manner:
for i, v := range js.Get("results").Array() {
fmt.Println(i, v)
}
func (*JSON) Bool ¶ added in v0.5.1
Bool guarantees the return of a `bool` (with optional default)
useful when you explicitly want a `bool` in a single value return context:
myFunc(js.Get("param1").Bool(), js.Get("optional_param").Bool(true))
func (*JSON) CheckArray ¶ added in v0.5.1
CheckArray type asserts to an `array`
func (*JSON) CheckFloat64 ¶ added in v0.5.1
CheckFloat64 coerces into a float64
func (*JSON) CheckGet ¶ added in v0.5.1
CheckGet is like Get, except it also returns a bool indicating whenever the branch was found or not the JSON pointer mai be nil
newJs, ok := js.Get("top_level", "entries", 3, "dict")
func (*JSON) CheckInt64 ¶ added in v0.5.1
CheckInt64 coerces into an int64
func (*JSON) CheckJSONArray ¶ added in v0.5.1
CheckJSONArray returns a copy of an array, but with each value as a JSON
func (*JSON) CheckJSONMap ¶ added in v0.5.1
CheckJSONMap returns a copy of a JSON map, but with values as Jsons
func (*JSON) CheckKeys ¶ added in v0.5.1
CheckKeys is like Keys, except it also returns a bool indicating if this `JSON` object is an map
func (*JSON) CheckString ¶ added in v0.5.1
CheckString type asserts to `string`
func (*JSON) CheckUint64 ¶ added in v0.5.1
CheckUint64 coerces into an uint64
func (*JSON) EncodePretty ¶ added in v0.5.1
EncodePretty returns its marshaled data as `[]byte` with indentation
func (*JSON) Float64 ¶ added in v0.5.1
Float64 guarantees the return of a `float64` (with optional default)
useful when you explicitly want a `float64` in a single value return context:
myFunc(js.Get("param1").Float64(), js.Get("optional_param").Float64(5.150))
func (*JSON) Get ¶ added in v0.5.1
Get searches for the item as specified by the branch within a nested JSON and returns a new JSON pointer the pointer is always a valid JSON, allowing for chained operations
newJs := js.Get("top_level", "entries", 3, "dict")
func (*JSON) Int ¶ added in v0.5.1
Int guarantees the return of an `int` (with optional default)
useful when you explicitly want an `int` in a single value return context:
myFunc(js.Get("param1").Int(), js.Get("optional_param").Int(5150))
func (*JSON) Int64 ¶ added in v0.5.1
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) Interface ¶ added in v0.5.1
func (j *JSON) Interface() interface{}
Interface returns the underlying data
func (*JSON) JSONArray ¶ added in v0.5.1
JSONArray guarantees the return of a `[]*JSON` (with optional default)
func (*JSON) JSONMap ¶ added in v0.5.1
JSONMap guarantees the return of a `map[string]*JSON` (with optional default)
func (*JSON) Map ¶ added in v0.5.1
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) MarshalJSON ¶ added in v0.5.1
Implements the json.Marshaler interface.
func (*JSON) Set ¶ added in v0.5.1
Set modifies `JSON` map by `key` and `value` Useful for changing single key/value in a `JSON` object easily.
func (*JSON) SetPath ¶ added in v0.5.1
SetPath modifies `JSON`, recursively checking/creating map keys for the supplied path, and then finally writing in the value
func (*JSON) String ¶ added in v0.5.1
String guarantees the return of a `string` (with optional default)
useful when you explicitly want a `string` in a single value return context:
myFunc(js.Get("param1").String(), js.Get("optional_param").String("my_default"))
func (*JSON) Uint64 ¶ added in v0.5.1
UInt64 guarantees the return of an `uint64` (with optional default)
useful when you explicitly want an `uint64` in a single value return context:
myFunc(js.Get("param1").Uint64(), js.Get("optional_param").Uint64(5150))
func (*JSON) UnmarshalJSON ¶ added in v0.5.1
Implements the json.Unmarshaler interface.
