json

package module
v0.0.0-...-b637437 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 27, 2019 License: MIT Imports: 12 Imported by: 0

README

###json

a Go package to interact with arbitrary JSON

Documentation

Index

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 FromBytes

func FromBytes(b []byte) (*Json, error)

FromBytes returns a pointer to a new `Json` object after unmarshaling `bytes`

func FromFile

func FromFile(file string) (*Json, error)

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

func FromReader(r io.Reader) (*Json, error)

FromReader returns a *Json by decoding from an io.Reader

func FromString

func FromString(str string) (*Json, error)

FromString returns a pointer to a new `Json` object after unmarshaling `str`

func MustFromBytes

func MustFromBytes(b []byte) *Json

MustFromBytes is a call to FromBytes with a panic on none nil error

func MustFromFile

func MustFromFile(file string) *Json

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

func MustFromReader(r io.Reader) *Json

MustFromReader is a call to FromReader with a panic on none nil error

func MustFromString

func MustFromString(str string) *Json

MustFromString is a call to FromString with a panic on none nil error

func MustNew

func MustNew() *Json

MustNew is a call to New with a panic on none nil error

func New

func New() (*Json, error)

New returns a pointer to a new, empty `Json` object

func (*Json) Bool

func (j *Json) Bool(path ...interface{}) (bool, error)

Bool type asserts to `bool`

func (*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))

func (*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,

func (*Json) Duration

func (j *Json) Duration(path ...interface{}) (time.Duration, error)

Duration type asserts to `time.Duration`

func (*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))

func (*Json) DurationSlice

func (j *Json) DurationSlice(path ...interface{}) ([]time.Duration, error)

DurationSlice type asserts to a `slice` of `time.Duration`

func (*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)
}

func (*Json) Float64

func (j *Json) Float64(path ...interface{}) (float64, error)

Float64 coerces into a float64

func (*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))

func (*Json) Float64Slice

func (j *Json) Float64Slice(path ...interface{}) ([]float64, error)

Float64Slice type asserts to a `slice` of `float64`

func (*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)
}

func (*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")

func (*Json) Int

func (j *Json) Int(path ...interface{}) (int, error)

Int coerces into an int

func (*Json) Int64

func (j *Json) Int64(path ...interface{}) (int64, error)

Int64 coerces into an int64

func (*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))

func (*Json) Int64Slice

func (j *Json) Int64Slice(path ...interface{}) ([]int64, error)

Int64Slice type asserts to a `slice` of `int64`

func (*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)
}

func (*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))

func (*Json) IntSlice

func (j *Json) IntSlice(path ...interface{}) ([]int, error)

IntSlice type asserts to a `slice` of `int`

func (*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)
}

func (*Json) Interface

func (j *Json) Interface(path ...interface{}) (interface{}, error)

Interface returns the underlying data

func (*Json) Map

func (j *Json) Map(path ...interface{}) (map[string]interface{}, error)

Map type asserts to `map[string]interface{}`

func (*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)
}

func (*Json) MapString

func (j *Json) MapString(path ...interface{}) (map[string]string, error)

Map type asserts to `map[string]string`

func (*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)
}

func (*Json) MarshalJSON

func (j *Json) MarshalJSON() ([]byte, error)

Implements the json.Marshaler interface.

func (*Json) MustBool

func (j *Json) MustBool(path ...interface{}) bool

MustBool is a call to Bool with a panic on none nil error

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

func (j *Json) MustDuration(path ...interface{}) time.Duration

MustDuration is a call to Duration with a panic on none nil error

func (*Json) MustDurationSlice

func (j *Json) MustDurationSlice(path ...interface{}) []time.Duration

MustDurationSlice is a call to DurationSlice with a panic on none nil error

func (*Json) MustFloat64

func (j *Json) MustFloat64(path ...interface{}) float64

MustFloat64 is a call to Float64 with a panic on none nil error

func (*Json) MustFloat64Slice

func (j *Json) MustFloat64Slice(path ...interface{}) []float64

MustFloat64Slice is a call to Float64Slice with a panic on none nil error

func (*Json) MustGet

func (j *Json) MustGet(path ...interface{}) *Json

MustGet is a call to Get with a panic on none nil error

func (*Json) MustInt

func (j *Json) MustInt(path ...interface{}) int

MustInt is a call to Int with a panic on none nil error

func (*Json) MustInt64

func (j *Json) MustInt64(path ...interface{}) int64

MustInt64 is a call to Int64 with a panic on none nil error

func (*Json) MustInt64Slice

func (j *Json) MustInt64Slice(path ...interface{}) []int64

MustInt64 is a call to Int64Slice with a panic on none nil error

func (*Json) MustIntSlice

func (j *Json) MustIntSlice(path ...interface{}) []int

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) MustMap

func (j *Json) MustMap(path ...interface{}) map[string]interface{}

MustMap is a call to Map with a panic on none nil error

func (*Json) MustMapString

func (j *Json) MustMapString(path ...interface{}) map[string]string

MustMapString is a call to MapString with a panic on none nil error

func (*Json) MustSet

func (j *Json) MustSet(pathPartsThenValue ...interface{}) *Json

MustSet is a call to Set 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

func (j *Json) MustString(path ...interface{}) string

MustString is a call to String with a panic on none nil error

func (*Json) MustStringSlice

func (j *Json) MustStringSlice(path ...interface{}) []string

MustStringSlice is a call to StringSlice with a panic on none nil error

func (*Json) MustTime

func (j *Json) MustTime(path ...interface{}) time.Time

MustTime is a call to Time with a panic on none nil error

func (*Json) MustTimeSlice

func (j *Json) MustTimeSlice(path ...interface{}) []time.Time

MustTimeSlice is a call to TimeSlice with a panic on none nil error

func (*Json) MustToBytes

func (j *Json) MustToBytes() []byte

MustToBytes is a call to ToBytes with a panic on none nil error

func (*Json) MustToFile

func (j *Json) MustToFile(file string, perm os.FileMode)

MustToFile is a call to ToFile with a panic on none nil error

func (*Json) MustToPrettyBytes

func (j *Json) MustToPrettyBytes() []byte

MustToPrettyBytes is a call to ToPrettyBytes with a panic on none nil error

func (*Json) MustToPrettyString

func (j *Json) MustToPrettyString() string

MustToPrettyString is a call to ToPrettyString with a panic on none nil error

func (*Json) MustToReader

func (j *Json) MustToReader() io.Reader

MustToReader is a call to ToReader with a panic on none nil error

func (*Json) MustToString

func (j *Json) MustToString() string

MustToString is a call to ToString with a panic on none nil error

func (*Json) MustUint64

func (j *Json) MustUint64(path ...interface{}) uint64

MustUint64 is a call to Uint64 with a panic on none nil error

func (*Json) MustUint64Slice

func (j *Json) MustUint64Slice(path ...interface{}) []uint64

MustUint64Slice is a call to Uint64Slice with a panic on none nil error

func (*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)

func (*Json) Slice

func (j *Json) Slice(path ...interface{}) ([]interface{}, error)

Slice type asserts to a `slice`

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) String

func (j *Json) String(path ...interface{}) (string, error)

String type asserts to `string`

func (*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"))

func (*Json) StringSlice

func (j *Json) StringSlice(path ...interface{}) ([]string, error)

StringSlice type asserts to a `slice` of `string`

func (*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)
}

func (*Json) Time

func (j *Json) Time(path ...interface{}) (time.Time, error)

Time type asserts to `time.Time`

func (*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))

func (*Json) TimeSlice

func (j *Json) TimeSlice(path ...interface{}) ([]time.Time, error)

TimeSlice type asserts to a `slice` of `time.Time`

func (*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)
}

func (*Json) ToBytes

func (j *Json) ToBytes() ([]byte, error)

ToBytes returns its marshaled data as `[]byte`

func (*Json) ToFile

func (j *Json) ToFile(file string, perm os.FileMode) error

ToFile writes the Json to the `file` with permission `perm`

func (*Json) ToPrettyBytes

func (j *Json) ToPrettyBytes() ([]byte, error)

ToPrettyBytes returns its marshaled data as `[]byte` with indentation

func (*Json) ToPrettyString

func (j *Json) ToPrettyString() (string, error)

ToPrettyString returns its marshaled data as `string` with indentation

func (*Json) ToReader

func (j *Json) ToReader() (io.Reader, error)

ToReader returns its marshaled data as `io.Reader`

func (*Json) ToString

func (j *Json) ToString() (string, error)

ToString returns its marshaled data as `string`

func (*Json) Uint64

func (j *Json) Uint64(path ...interface{}) (uint64, error)

Uint64 coerces into an uint64

func (*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))

func (*Json) Uint64Slice

func (j *Json) Uint64Slice(path ...interface{}) ([]uint64, error)

Uint64Slice type asserts to a `slice` of `uint64`

func (*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)
}

func (*Json) UnmarshalJSON

func (j *Json) UnmarshalJSON(p []byte) error

Implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL