json
v0.0.0-20190227171909-b63743726170
Documentation
pkg.go.dev ↗Types
Json
type Json struct {
// contains filtered or unexported fields
}
FromBytes
func FromBytes(b []byte) (*Json, error)
FromBytes returns a pointer to a new `Json` object after unmarshaling `bytes`
FromFile
func FromFile(file string) (*Json, error)
FromFile returns a pointer to a new `Json` object after unmarshaling the contents from `file` into it
FromInterface
func FromInterface(i interface{}) *Json
FromInterface returns a pointer to a new `Json` object after assigning `i` to its internal data
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
FromReader
func FromReader(r io.Reader) (*Json, error)
FromReader returns a *Json by decoding from an io.Reader
FromString
func FromString(str string) (*Json, error)
FromString returns a pointer to a new `Json` object after unmarshaling `str`
MustFromBytes
func MustFromBytes(b []byte) *Json
MustFromBytes is a call to FromBytes with a panic on none nil error
MustFromFile
func MustFromFile(file string) *Json
MustFromFile is a call to FromFile with a panic on none nil error
MustFromReadCloser
func MustFromReadCloser(rc io.ReadCloser) *Json
MustFromReadCloser is a call to FromReadCloser with a panic on none nil error
MustFromReader
func MustFromReader(r io.Reader) *Json
MustFromReader is a call to FromReader with a panic on none nil error
MustFromString
func MustFromString(str string) *Json
MustFromString is a call to FromString with a panic on none nil error
MustNew
func MustNew() *Json
MustNew is a call to New with a panic on none nil error
New
func New() (*Json, error)
New returns a pointer to a new, empty `Json` object
Json.Bool
func (j *Json) Bool(path ...interface{}) (bool, error)
Bool type asserts to `bool`
Json.BoolOrDefault
func (j *Json) BoolOrDefault(def bool, path ...interface{}) bool
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))
Json.Del
func (j *Json) Del(path ...interface{}) error
Del modifies `Json` maps and slices by deleting/removing the last `path` segment if it is present,
Json.Duration
func (j *Json) Duration(path ...interface{}) (time.Duration, error)
Duration type asserts to `time.Duration`
Json.DurationOrDefault
func (j *Json) DurationOrDefault(def time.Duration, path ...interface{}) time.Duration
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))
Json.DurationSlice
func (j *Json) DurationSlice(path ...interface{}) ([]time.Duration, error)
DurationSlice type asserts to a `slice` of `time.Duration`
Json.DurationSliceOrDefault
func (j *Json) DurationSliceOrDefault(def []time.Duration, path ...interface{}) []time.Duration
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)
}
Json.Float64
func (j *Json) Float64(path ...interface{}) (float64, error)
Float64 coerces into a float64
Json.Float64OrDefault
func (j *Json) Float64OrDefault(def float64, path ...interface{}) float64
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))
Json.Float64Slice
func (j *Json) Float64Slice(path ...interface{}) ([]float64, error)
Float64Slice type asserts to a `slice` of `float64`
Json.Float64SliceOrDefault
func (j *Json) Float64SliceOrDefault(def []float64, path ...interface{}) []float64
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)
}
Json.Get
func (j *Json) Get(path ...interface{}) (*Json, error)
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")
Json.Int
func (j *Json) Int(path ...interface{}) (int, error)
Int coerces into an int
Json.Int64
func (j *Json) Int64(path ...interface{}) (int64, error)
Int64 coerces into an int64
Json.Int64OrDefault
func (j *Json) Int64OrDefault(def int64, path ...interface{}) int64
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))
Json.Int64Slice
func (j *Json) Int64Slice(path ...interface{}) ([]int64, error)
Int64Slice type asserts to a `slice` of `int64`
Json.Int64SliceDefault
func (j *Json) Int64SliceDefault(def []int64, path ...interface{}) []int64
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)
}
Json.IntOrDefault
func (j *Json) IntOrDefault(def int, path ...interface{}) int
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))
Json.IntSlice
func (j *Json) IntSlice(path ...interface{}) ([]int, error)
IntSlice type asserts to a `slice` of `int`
Json.IntSliceOrDefault
func (j *Json) IntSliceOrDefault(def []int, path ...interface{}) []int
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)
}
Json.Interface
func (j *Json) Interface(path ...interface{}) (interface{}, error)
Interface returns the underlying data
Json.Map
func (j *Json) Map(path ...interface{}) (map[string]interface{}, error)
Map type asserts to `map[string]interface{}`
Json.MapOrDefault
func (j *Json) MapOrDefault(def map[string]interface{}, path ...interface{}) map[string]interface{}
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)
}
Json.MapString
func (j *Json) MapString(path ...interface{}) (map[string]string, error)
Map type asserts to `map[string]string`
Json.MapStringOrDefault
func (j *Json) MapStringOrDefault(def map[string]string, path ...interface{}) map[string]string
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)
}
Json.MarshalJSON
func (j *Json) MarshalJSON() ([]byte, error)
Implements the json.Marshaler interface.
Json.MustBool
func (j *Json) MustBool(path ...interface{}) bool
MustBool is a call to Bool with a panic on none nil error
Json.MustDel
func (j *Json) MustDel(path ...interface{})
MustDel is a call to Del with a panic on none nil error
Json.MustDuration
func (j *Json) MustDuration(path ...interface{}) time.Duration
MustDuration is a call to Duration with a panic on none nil error
Json.MustDurationSlice
func (j *Json) MustDurationSlice(path ...interface{}) []time.Duration
MustDurationSlice is a call to DurationSlice with a panic on none nil error
Json.MustFloat64
func (j *Json) MustFloat64(path ...interface{}) float64
MustFloat64 is a call to Float64 with a panic on none nil error
Json.MustFloat64Slice
func (j *Json) MustFloat64Slice(path ...interface{}) []float64
MustFloat64Slice is a call to Float64Slice with a panic on none nil error
Json.MustGet
func (j *Json) MustGet(path ...interface{}) *Json
MustGet is a call to Get with a panic on none nil error
Json.MustInt
func (j *Json) MustInt(path ...interface{}) int
MustInt is a call to Int with a panic on none nil error
Json.MustInt64
func (j *Json) MustInt64(path ...interface{}) int64
MustInt64 is a call to Int64 with a panic on none nil error
Json.MustInt64Slice
func (j *Json) MustInt64Slice(path ...interface{}) []int64
MustInt64 is a call to Int64Slice with a panic on none nil error
Json.MustIntSlice
func (j *Json) MustIntSlice(path ...interface{}) []int
MustIntSlice is a call to IntSlice with a panic on none nil error
Json.MustInterface
func (j *Json) MustInterface(path ...interface{}) interface{}
MustInterface is a call to Interface with a panic on none nil error
Json.MustMap
func (j *Json) MustMap(path ...interface{}) map[string]interface{}
MustMap is a call to Map with a panic on none nil error
Json.MustMapString
func (j *Json) MustMapString(path ...interface{}) map[string]string
MustMapString is a call to MapString with a panic on none nil error
Json.MustSet
func (j *Json) MustSet(pathPartsThenValue ...interface{}) *Json
MustSet is a call to Set with a panic on none nil error
Json.MustSlice
func (j *Json) MustSlice(path ...interface{}) []interface{}
MustSlice is a call to MustSlice with a panic on none nil error
Json.MustString
func (j *Json) MustString(path ...interface{}) string
MustString is a call to String with a panic on none nil error
Json.MustStringSlice
func (j *Json) MustStringSlice(path ...interface{}) []string
MustStringSlice is a call to StringSlice with a panic on none nil error
Json.MustTime
func (j *Json) MustTime(path ...interface{}) time.Time
MustTime is a call to Time with a panic on none nil error
Json.MustTimeSlice
func (j *Json) MustTimeSlice(path ...interface{}) []time.Time
MustTimeSlice is a call to TimeSlice with a panic on none nil error
Json.MustToBytes
func (j *Json) MustToBytes() []byte
MustToBytes is a call to ToBytes with a panic on none nil error
Json.MustToFile
func (j *Json) MustToFile(file string, perm os.FileMode)
MustToFile is a call to ToFile with a panic on none nil error
Json.MustToPrettyBytes
func (j *Json) MustToPrettyBytes() []byte
MustToPrettyBytes is a call to ToPrettyBytes with a panic on none nil error
Json.MustToPrettyString
func (j *Json) MustToPrettyString() string
MustToPrettyString is a call to ToPrettyString with a panic on none nil error
Json.MustToReader
func (j *Json) MustToReader() io.Reader
MustToReader is a call to ToReader with a panic on none nil error
Json.MustToString
func (j *Json) MustToString() string
MustToString is a call to ToString with a panic on none nil error
Json.MustUint64
func (j *Json) MustUint64(path ...interface{}) uint64
MustUint64 is a call to Uint64 with a panic on none nil error
Json.MustUint64Slice
func (j *Json) MustUint64Slice(path ...interface{}) []uint64
MustUint64Slice is a call to Uint64Slice with a panic on none nil error
Json.Set
func (j *Json) Set(pathPartsThenValue ...interface{}) error
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)
Json.Slice
func (j *Json) Slice(path ...interface{}) ([]interface{}, error)
Slice type asserts to a `slice`
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)
}
Json.String
func (j *Json) String(path ...interface{}) (string, error)
String type asserts to `string`
Json.StringOrDefault
func (j *Json) StringOrDefault(def string, path ...interface{}) string
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"))
Json.StringSlice
func (j *Json) StringSlice(path ...interface{}) ([]string, error)
StringSlice type asserts to a `slice` of `string`
Json.StringSliceOrDefault
func (j *Json) StringSliceOrDefault(def []string, path ...interface{}) []string
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)
}
Json.Time
func (j *Json) Time(path ...interface{}) (time.Time, error)
Time type asserts to `time.Time`
Json.TimeOrDefault
func (j *Json) TimeOrDefault(def time.Time, path ...interface{}) time.Time
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))
Json.TimeSlice
func (j *Json) TimeSlice(path ...interface{}) ([]time.Time, error)
TimeSlice type asserts to a `slice` of `time.Time`
Json.TimeSliceOrDefault
func (j *Json) TimeSliceOrDefault(def []time.Time, path ...interface{}) []time.Time
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)
}
Json.ToBytes
func (j *Json) ToBytes() ([]byte, error)
ToBytes returns its marshaled data as `[]byte`
Json.ToFile
func (j *Json) ToFile(file string, perm os.FileMode) error
ToFile writes the Json to the `file` with permission `perm`
Json.ToPrettyBytes
func (j *Json) ToPrettyBytes() ([]byte, error)
ToPrettyBytes returns its marshaled data as `[]byte` with indentation
Json.ToPrettyString
func (j *Json) ToPrettyString() (string, error)
ToPrettyString returns its marshaled data as `string` with indentation
Json.ToReader
func (j *Json) ToReader() (io.Reader, error)
ToReader returns its marshaled data as `io.Reader`
Json.ToString
func (j *Json) ToString() (string, error)
ToString returns its marshaled data as `string`
Json.Uint64
func (j *Json) Uint64(path ...interface{}) (uint64, error)
Uint64 coerces into an uint64
Json.Uint64OrDefault
func (j *Json) Uint64OrDefault(def uint64, path ...interface{}) uint64
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))
Json.Uint64Slice
func (j *Json) Uint64Slice(path ...interface{}) ([]uint64, error)
Uint64Slice type asserts to a `slice` of `uint64`
Json.Uint64SliceOrDefault
func (j *Json) Uint64SliceOrDefault(def []uint64, path ...interface{}) []uint64
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)
}
Json.UnmarshalJSON
func (j *Json) UnmarshalJSON(p []byte) error
Implements the json.Unmarshaler interface.