simplejson

package
v1.17.0 Latest Latest
Warning

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

Go to latest
Published: Sep 1, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

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 MustJSON

func MustJSON(body []byte) *JSON

MustJSON returns a pointer to a new `JSON` object after unmarshalling `body` bytes, panic if error occurred.

func New

func New() *JSON

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

func NewArray

func NewArray() *JSON

NewArray returns a pointer to a new, empty `JSON` array

func NewFrom

func NewFrom(i interface{}) *JSON

NewFrom returns a pointer to the json object converted from any other object.

func NewFromReader

func NewFromReader(r io.Reader) (*JSON, error)

NewFromReader returns a *JSON by decoding from an io.Reader

func NewJSON

func NewJSON(body []byte) (*JSON, error)

NewJSON returns a pointer to a new `JSON` object after unmarshalling `body` bytes

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

func (j *JSON) Bool(args ...bool) 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

func (j *JSON) CheckArray() ([]interface{}, bool)

CheckArray type asserts to an `array`

func (*JSON) CheckBool

func (j *JSON) CheckBool() (bool, bool)

CheckBool type asserts to `bool`

func (*JSON) CheckFloat64

func (j *JSON) CheckFloat64() (float64, bool)

CheckFloat64 coerces into a float64

func (*JSON) CheckGet

func (j *JSON) CheckGet(branch ...interface{}) (*JSON, bool)

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

func (j *JSON) CheckInt() (int, bool)

CheckInt coerces into an int

func (*JSON) CheckInt64

func (j *JSON) CheckInt64() (int64, bool)

CheckInt64 coerces into an int64

func (*JSON) CheckJSONArray

func (j *JSON) CheckJSONArray() ([]*JSON, bool)

CheckJSONArray returns a copy of an array, but with each value as a JSON

func (*JSON) CheckJSONMap

func (j *JSON) CheckJSONMap() (map[string]*JSON, bool)

CheckJSONMap returns a copy of a JSON map, but with values as Jsons

func (*JSON) CheckMap

func (j *JSON) CheckMap() (map[string]interface{}, bool)

CheckMap type asserts to `map`

func (*JSON) CheckString

func (j *JSON) CheckString() (string, bool)

CheckString type asserts to `string`

func (*JSON) CheckUint64

func (j *JSON) CheckUint64() (uint64, bool)

CheckUint64 coerces into an uint64

func (*JSON) Del

func (j *JSON) Del(key string)

Del modifies `JSON` map by deleting `key` if it is present.

func (*JSON) Float64

func (j *JSON) Float64(args ...float64) 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

func (j *JSON) Get(branch ...interface{}) *JSON

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

func (j *JSON) Int(args ...int) 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

func (j *JSON) Int64(args ...int64) 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) IsNull

func (j *JSON) IsNull() bool

IsNull returns true if the value is null.

func (*JSON) JSONArray

func (j *JSON) JSONArray(args ...[]*JSON) []*JSON

JSONArray guarantees the return of a `[]*JSON` (with optional default)

func (*JSON) JSONMap

func (j *JSON) JSONMap(args ...map[string]*JSON) map[string]*JSON

JSONMap guarantees the return of a `map[string]*JSON` (with optional default)

func (*JSON) Map

func (j *JSON) Map(args ...map[string]interface{}) map[string]interface{}

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 (j JSON) MarshalBinary() (data []byte, err error)

func (*JSON) MarshalJSON

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

MarshalJSON implements the json.Marshaller interface.

func (*JSON) MarshalString

func (j *JSON) MarshalString() string

func (*JSON) Scan

func (j *JSON) Scan(value interface{}) error

Scan scans value into Json, implements sql.Scanner interface.

func (*JSON) Set

func (j *JSON) Set(key string, val interface{})

Set modifies `JSON` map by `key` and `value` Useful for changing single key/value in a `JSON` object easily.

func (*JSON) SetPath

func (j *JSON) SetPath(branch []string, val interface{})

SetPath modifies `JSON`, recursively checking/creating map keys for the supplied path, and then finally writing in the value

func (*JSON) String

func (j *JSON) String(args ...string) 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 (j *JSON) StringOrNil(args ...string) *string

func (*JSON) Uint64

func (j *JSON) Uint64(args ...uint64) 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

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

UnmarshalJSON implements the json.Unmarshaler interface.

func (JSON) Value

func (j JSON) Value() (driver.Value, error)

Value returns json value, implement driver.Valuer interface.

Jump to

Keyboard shortcuts

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