Documentation ¶
Index ¶
- 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) 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) 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) IsNull() bool
- func (j *JSON) JSONArray(args ...[]*JSON) []*JSON
- func (j *JSON) JSONMap(args ...map[string]*JSON) map[string]*JSON
- func (j *JSON) Map(args ...map[string]interface{}) map[string]interface{}
- func (j JSON) MarshalBinary() (data []byte, err error)
- func (j *JSON) MarshalJSON() ([]byte, error)
- func (j *JSON) MarshalString() string
- func (j *JSON) Scan(value interface{}) 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) StringOrNil(args ...string) *string
- func (j *JSON) Uint64(args ...uint64) uint64
- func (j *JSON) UnmarshalJSON(p []byte) error
- func (j JSON) Value() (driver.Value, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
func MustJSON ¶
MustJSON returns a pointer to a new `JSON` object after unmarshalling `body` bytes, panic if error occurred.
func NewFrom ¶
func NewFrom(i interface{}) *JSON
NewFrom returns a pointer to the json object converted from any other object.
func NewFromReader ¶
NewFromReader returns a *JSON by decoding from an io.Reader
func (*JSON) Array ¶
func (j *JSON) Array(args ...[]interface{}) []interface{}
Array guarantees the return of a `[]interface{}` (with optional default)
useful when you want to iterate over array values in a succinct manner:
for i, v := range js.Get("results").Array() { fmt.Println(i, v) }
func (*JSON) Bool ¶
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 ¶
CheckArray type asserts to an `array`
func (*JSON) CheckFloat64 ¶
CheckFloat64 coerces into a float64
func (*JSON) CheckGet ¶
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 ¶
CheckInt64 coerces into an int64
func (*JSON) CheckJSONArray ¶
CheckJSONArray returns a copy of an array, but with each value as a JSON
func (*JSON) CheckJSONMap ¶
CheckJSONMap returns a copy of a JSON map, but with values as Jsons
func (*JSON) CheckString ¶
CheckString type asserts to `string`
func (*JSON) CheckUint64 ¶
CheckUint64 coerces into an uint64
func (*JSON) Float64 ¶
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 ¶
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 ¶
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 ¶
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 ¶
func (j *JSON) Interface() interface{}
Interface returns the underlying data
func (*JSON) JSONMap ¶
JSONMap guarantees the return of a `map[string]*JSON` (with optional default)
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) MarshalBinary ¶
func (*JSON) MarshalJSON ¶
MarshalJSON implements the json.Marshaller interface.
func (*JSON) MarshalString ¶
func (*JSON) Set ¶
Set modifies `JSON` map by `key` and `value` Useful for changing single key/value in a `JSON` object easily.
func (*JSON) SetPath ¶
SetPath modifies `JSON`, recursively checking/creating map keys for the supplied path, and then finally writing in the value
func (*JSON) String ¶
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) StringOrNil ¶
func (*JSON) Uint64 ¶
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 ¶
UnmarshalJSON implements the json.Unmarshaler interface.