Documentation ¶
Index ¶
- type Json
- func FromBytes(b []byte) (*Json, error)
- func FromFile(file string) (*Json, error)
- func FromInterface(i interface{}) *Json
- func FromReadCloser(rc io.ReadCloser) (*Json, error)
- func FromReader(r io.Reader) (*Json, error)
- func FromString(str string) (*Json, error)
- func MustFromBytes(b []byte) *Json
- func MustFromFile(file string) *Json
- func MustFromReadCloser(rc io.ReadCloser) *Json
- func MustFromReader(r io.Reader) *Json
- func MustFromString(str string) *Json
- func MustNew() *Json
- func New() (*Json, error)
- func (j *Json) Bool(path ...interface{}) (bool, error)
- func (j *Json) BoolOrDefault(def bool, path ...interface{}) bool
- func (j *Json) Del(path ...interface{}) error
- func (j *Json) Duration(path ...interface{}) (time.Duration, error)
- func (j *Json) DurationOrDefault(def time.Duration, path ...interface{}) time.Duration
- func (j *Json) DurationSlice(path ...interface{}) ([]time.Duration, error)
- func (j *Json) DurationSliceOrDefault(def []time.Duration, path ...interface{}) []time.Duration
- func (j *Json) Float64(path ...interface{}) (float64, error)
- func (j *Json) Float64OrDefault(def float64, path ...interface{}) float64
- func (j *Json) Float64Slice(path ...interface{}) ([]float64, error)
- func (j *Json) Float64SliceOrDefault(def []float64, path ...interface{}) []float64
- func (j *Json) Get(path ...interface{}) (*Json, error)
- func (j *Json) Int(path ...interface{}) (int, error)
- func (j *Json) Int64(path ...interface{}) (int64, error)
- func (j *Json) Int64OrDefault(def int64, path ...interface{}) int64
- func (j *Json) Int64Slice(path ...interface{}) ([]int64, error)
- func (j *Json) Int64SliceDefault(def []int64, path ...interface{}) []int64
- func (j *Json) IntOrDefault(def int, path ...interface{}) int
- func (j *Json) IntSlice(path ...interface{}) ([]int, error)
- func (j *Json) IntSliceOrDefault(def []int, path ...interface{}) []int
- func (j *Json) Interface(path ...interface{}) (interface{}, error)
- func (j *Json) Map(path ...interface{}) (map[string]interface{}, error)
- func (j *Json) MapOrDefault(def map[string]interface{}, path ...interface{}) map[string]interface{}
- func (j *Json) MapString(path ...interface{}) (map[string]string, error)
- func (j *Json) MapStringOrDefault(def map[string]string, path ...interface{}) map[string]string
- func (j *Json) MarshalJSON() ([]byte, error)
- func (j *Json) MustBool(path ...interface{}) bool
- func (j *Json) MustDel(path ...interface{})
- func (j *Json) MustDuration(path ...interface{}) time.Duration
- func (j *Json) MustDurationSlice(path ...interface{}) []time.Duration
- func (j *Json) MustFloat64(path ...interface{}) float64
- func (j *Json) MustFloat64Slice(path ...interface{}) []float64
- func (j *Json) MustGet(path ...interface{}) *Json
- func (j *Json) MustInt(path ...interface{}) int
- func (j *Json) MustInt64(path ...interface{}) int64
- func (j *Json) MustInt64Slice(path ...interface{}) []int64
- func (j *Json) MustIntSlice(path ...interface{}) []int
- func (j *Json) MustInterface(path ...interface{}) interface{}
- func (j *Json) MustMap(path ...interface{}) map[string]interface{}
- func (j *Json) MustMapString(path ...interface{}) map[string]string
- func (j *Json) MustSet(pathPartsThenValue ...interface{}) *Json
- func (j *Json) MustSlice(path ...interface{}) []interface{}
- func (j *Json) MustString(path ...interface{}) string
- func (j *Json) MustStringSlice(path ...interface{}) []string
- func (j *Json) MustTime(path ...interface{}) time.Time
- func (j *Json) MustTimeSlice(path ...interface{}) []time.Time
- func (j *Json) MustToBytes() []byte
- func (j *Json) MustToFile(file string, perm os.FileMode)
- func (j *Json) MustToPrettyBytes() []byte
- func (j *Json) MustToPrettyString() string
- func (j *Json) MustToReader() io.Reader
- func (j *Json) MustToString() string
- func (j *Json) MustUint64(path ...interface{}) uint64
- func (j *Json) MustUint64Slice(path ...interface{}) []uint64
- func (j *Json) Set(pathPartsThenValue ...interface{}) error
- func (j *Json) Slice(path ...interface{}) ([]interface{}, error)
- func (j *Json) SliceOrDefault(def []interface{}, path ...interface{}) []interface{}
- func (j *Json) String(path ...interface{}) (string, error)
- func (j *Json) StringOrDefault(def string, path ...interface{}) string
- func (j *Json) StringSlice(path ...interface{}) ([]string, error)
- func (j *Json) StringSliceOrDefault(def []string, path ...interface{}) []string
- func (j *Json) Time(path ...interface{}) (time.Time, error)
- func (j *Json) TimeOrDefault(def time.Time, path ...interface{}) time.Time
- func (j *Json) TimeSlice(path ...interface{}) ([]time.Time, error)
- func (j *Json) TimeSliceOrDefault(def []time.Time, path ...interface{}) []time.Time
- func (j *Json) ToBytes() ([]byte, error)
- func (j *Json) ToFile(file string, perm os.FileMode) error
- func (j *Json) ToPrettyBytes() ([]byte, error)
- func (j *Json) ToPrettyString() (string, error)
- func (j *Json) ToReader() (io.Reader, error)
- func (j *Json) ToString() (string, error)
- func (j *Json) Uint64(path ...interface{}) (uint64, error)
- func (j *Json) Uint64OrDefault(def uint64, path ...interface{}) uint64
- func (j *Json) Uint64Slice(path ...interface{}) ([]uint64, error)
- func (j *Json) Uint64SliceOrDefault(def []uint64, path ...interface{}) []uint64
- func (j *Json) UnmarshalJSON(p []byte) 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 FromFile ¶
FromFile returns a pointer to a new `Json` object after unmarshaling the contents from `file` into it
func FromInterface ¶
func FromInterface(i interface{}) *Json
FromInterface returns a pointer to a new `Json` object after assigning `i` to its internal data
func FromReadCloser ¶
func FromReadCloser(rc io.ReadCloser) (*Json, error)
FromReadCloser returns a *Json by decoding from an io.ReadCloser and calls the io.ReadCloser Close method
func FromReader ¶
FromReader returns a *Json by decoding from an io.Reader
func FromString ¶
FromString returns a pointer to a new `Json` object after unmarshaling `str`
func MustFromBytes ¶
MustFromBytes is a call to FromBytes with a panic on none nil error
func MustFromFile ¶
MustFromFile is a call to FromFile with a panic on none nil error
func MustFromReadCloser ¶
func MustFromReadCloser(rc io.ReadCloser) *Json
MustFromReadCloser is a call to FromReadCloser with a panic on none nil error
func MustFromReader ¶
MustFromReader is a call to FromReader with a panic on none nil error
func MustFromString ¶
MustFromString is a call to FromString with a panic on none nil error
func (*Json) BoolOrDefault ¶
BoolOrDefault guarantees the return of a `bool` (with specified default)
useful when you explicitly want a `bool` in a single value return context:
myFunc(js.BoolOrDefault(true))
func (*Json) Del ¶
Del modifies `Json` maps and slices by deleting/removing the last `path` segment if it is present,
func (*Json) DurationOrDefault ¶
DurationOrDefault guarantees the return of a `time.Duration` (with specified default)
useful when you explicitly want a `time.Duration` in a single value return context:
myFunc(js.DurationOrDefault(defaultDuration))
func (*Json) DurationSlice ¶
DurationSlice type asserts to a `slice` of `time.Duration`
func (*Json) DurationSliceOrDefault ¶
DurationSliceOrDefault guarantees the return of a `[]time.Duration` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, t := range js.DurationSliceOrDefault(nil) { fmt.Println(i, t) }
func (*Json) Float64OrDefault ¶
Float64OrDefault guarantees the return of a `float64` (with specified default)
useful when you explicitly want a `float64` in a single value return context:
myFunc(js.Float64OrDefault(5.150))
func (*Json) Float64Slice ¶
Float64Slice type asserts to a `slice` of `float64`
func (*Json) Float64SliceOrDefault ¶
Float64SliceOrDefault guarantees the return of a `[]float64` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, s := range js.Float64SliceOrDefault(nil) { fmt.Println(i, s) }
func (*Json) Get ¶
Get searches for the item as specified by the path. path can contain strings or ints to navigate through json objects and slices. If the given path is not present then the deepest valid value is returned along with an error.
js.Get("top_level", "dict", 3, "foo")
func (*Json) Int64OrDefault ¶
Int64OrDefault guarantees the return of an `int64` (with specified default)
useful when you explicitly want an `int64` in a single value return context:
myFunc(js.Int64OrDefault(5150))
func (*Json) Int64Slice ¶
Int64Slice type asserts to a `slice` of `int64`
func (*Json) Int64SliceDefault ¶
Int64SliceDefault guarantees the return of a `[]int64` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, s := range js.Int64SliceDefault(nil) { fmt.Println(i, s) }
func (*Json) IntOrDefault ¶
IntOrDefault guarantees the return of an `int` (with specified default)
useful when you explicitly want an `int` in a single value return context:
myFunc(js.IntOrDefault(5150))
func (*Json) IntSliceOrDefault ¶
IntSliceOrDefault guarantees the return of a `[]int` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, s := range js.IntSliceOrDefault(nil) { fmt.Println(i, s) }
func (*Json) MapOrDefault ¶
MapOrDefault guarantees the return of a `map[string]interface{}` (with specified default)
useful when you want to iterate over map values in a succinct manner:
for k, v := range js.MapOrDefault(nil) { fmt.Println(k, v) }
func (*Json) MapStringOrDefault ¶
MapStringOrDefault guarantees the return of a `map[string]string{}` (with specified default)
useful when you want to iterate over map values in a succinct manner:
for k, v := range js.MapStringOrDefault(nil) { fmt.Println(k, v) }
func (*Json) MarshalJSON ¶
Implements the json.Marshaler interface.
func (*Json) MustDel ¶
func (j *Json) MustDel(path ...interface{})
MustDel is a call to Del with a panic on none nil error
func (*Json) MustDuration ¶
MustDuration is a call to Duration with a panic on none nil error
func (*Json) MustDurationSlice ¶
MustDurationSlice is a call to DurationSlice with a panic on none nil error
func (*Json) MustFloat64 ¶
MustFloat64 is a call to Float64 with a panic on none nil error
func (*Json) MustFloat64Slice ¶
MustFloat64Slice is a call to Float64Slice with a panic on none nil error
func (*Json) MustInt64Slice ¶
MustInt64 is a call to Int64Slice with a panic on none nil error
func (*Json) MustIntSlice ¶
MustIntSlice is a call to IntSlice with a panic on none nil error
func (*Json) MustInterface ¶
func (j *Json) MustInterface(path ...interface{}) interface{}
MustInterface is a call to Interface with a panic on none nil error
func (*Json) MustMapString ¶
MustMapString is a call to MapString with a panic on none nil error
func (*Json) MustSlice ¶
func (j *Json) MustSlice(path ...interface{}) []interface{}
MustSlice is a call to MustSlice with a panic on none nil error
func (*Json) MustString ¶
MustString is a call to String with a panic on none nil error
func (*Json) MustStringSlice ¶
MustStringSlice is a call to StringSlice with a panic on none nil error
func (*Json) MustTimeSlice ¶
MustTimeSlice is a call to TimeSlice with a panic on none nil error
func (*Json) MustToBytes ¶
MustToBytes is a call to ToBytes with a panic on none nil error
func (*Json) MustToFile ¶
MustToFile is a call to ToFile with a panic on none nil error
func (*Json) MustToPrettyBytes ¶
MustToPrettyBytes is a call to ToPrettyBytes with a panic on none nil error
func (*Json) MustToPrettyString ¶
MustToPrettyString is a call to ToPrettyString with a panic on none nil error
func (*Json) MustToReader ¶
MustToReader is a call to ToReader with a panic on none nil error
func (*Json) MustToString ¶
MustToString is a call to ToString with a panic on none nil error
func (*Json) MustUint64 ¶
MustUint64 is a call to Uint64 with a panic on none nil error
func (*Json) MustUint64Slice ¶
MustUint64Slice is a call to Uint64Slice with a panic on none nil error
func (*Json) Set ¶
Set modifies `Json`, recursively checking/creating map keys and checking slice indices for the supplied path, and then finally writing in the value. Set will only create maps where the current map[key] does not exist, if the key exists, even if the value is nil, a new map will not be created and an error wil be returned.
j.Set("my", "path", 1, "to-the", "property", value)
func (*Json) SliceOrDefault ¶
func (j *Json) SliceOrDefault(def []interface{}, path ...interface{}) []interface{}
SliceOrDefault guarantees the return of a `[]interface{}` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, v := range js.SliceOrDefault(nil) { fmt.Println(i, v) }
func (*Json) StringOrDefault ¶
StringOrDefault guarantees the return of a `string` (with specified default)
useful when you explicitly want a `string` in a single value return context:
myFunc(js.StringOrDefault("my_default"))
func (*Json) StringSlice ¶
StringSlice type asserts to a `slice` of `string`
func (*Json) StringSliceOrDefault ¶
StringSliceOrDefault guarantees the return of a `[]string` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, s := range js.StringSliceOrDefault(nil) { fmt.Println(i, s) }
func (*Json) TimeOrDefault ¶
TimeOrDefault guarantees the return of a `time.Time` (with specified default)
useful when you explicitly want a `time.Time` in a single value return context:
myFunc(js.TimeOrDefault(defaultTime))
func (*Json) TimeSliceOrDefault ¶
TimeSliceOrDefault guarantees the return of a `[]time.Time` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, t := range js.TimeSliceOrDefault(nil) { fmt.Println(i, t) }
func (*Json) ToPrettyBytes ¶
ToPrettyBytes returns its marshaled data as `[]byte` with indentation
func (*Json) ToPrettyString ¶
ToPrettyString returns its marshaled data as `string` with indentation
func (*Json) Uint64OrDefault ¶
MustUInt64 guarantees the return of an `uint64` (with specified default)
useful when you explicitly want an `uint64` in a single value return context:
myFunc(js.Uint64OrDefault(5150))
func (*Json) Uint64Slice ¶
Uint64Slice type asserts to a `slice` of `uint64`
func (*Json) Uint64SliceOrDefault ¶
Uint64SliceOrDefault guarantees the return of a `[]uint64` (with specified default)
useful when you want to iterate over slice values in a succinct manner:
for i, s := range js.Uint64SliceOrDefault(nil) { fmt.Println(i, s) }
func (*Json) UnmarshalJSON ¶
Implements the json.Unmarshaler interface.