simplejson

package module
v0.5.1 Latest Latest
Warning

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

Go to latest
Published: May 24, 2018 License: MIT Imports: 6 Imported by: 0

README

go-simplejson

a Go package to interact with arbitrary JSON

Build Status GoDoc

Importing

import github.com/AzuraMeta/go-simplejson

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Version

func Version() string

returns the current implementation version

Types

type JSON added in v0.5.1

type JSON struct {
	// contains filtered or unexported fields
}

func New added in v0.5.0

func New() *JSON

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

func NewFromReader added in v0.5.0

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

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

func NewJSON added in v0.5.1

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

NewJson returns a pointer to a new `JSON` object after unmarshaling `body` bytes

func (*JSON) Array added in v0.5.1

func (j *JSON) Array(args ...[]interface{}) []interface{}

Array guarantees the return of a `[]interface{}` (with optional default)

useful when you want to interate over array values in a succinct manner:

for i, v := range js.Get("results").Array() {
	fmt.Println(i, v)
}

func (*JSON) Bool added in v0.5.1

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 added in v0.5.1

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

CheckArray type asserts to an `array`

func (*JSON) CheckBool added in v0.5.1

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

CheckBool type asserts to `bool`

func (*JSON) CheckFloat64 added in v0.5.1

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

CheckFloat64 coerces into a float64

func (*JSON) CheckGet added in v0.5.1

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 added in v0.5.1

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

CheckInt coerces into an int

func (*JSON) CheckInt64 added in v0.5.1

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

CheckInt64 coerces into an int64

func (*JSON) CheckJSONArray added in v0.5.1

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

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

func (*JSON) CheckJSONMap added in v0.5.1

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

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

func (*JSON) CheckKeys added in v0.5.1

func (j *JSON) CheckKeys() ([]string, bool)

CheckKeys is like Keys, except it also returns a bool indicating if this `JSON` object is an map

func (*JSON) CheckMap added in v0.5.1

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

CheckMap type asserts to `map`

func (*JSON) CheckString added in v0.5.1

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

CheckString type asserts to `string`

func (*JSON) CheckUint64 added in v0.5.1

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

CheckUint64 coerces into an uint64

func (*JSON) Del added in v0.5.1

func (j *JSON) Del(key string)

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

func (*JSON) Encode added in v0.5.1

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

Encode returns its marshaled data as `[]byte`

func (*JSON) EncodePretty added in v0.5.1

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

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

func (*JSON) Float64 added in v0.5.1

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 added in v0.5.1

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 added in v0.5.1

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 added in v0.5.1

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 added in v0.5.1

func (j *JSON) Interface() interface{}

Interface returns the underlying data

func (*JSON) JSONArray added in v0.5.1

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

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

func (*JSON) JSONMap added in v0.5.1

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) Keys added in v0.5.1

func (j *JSON) Keys() []string

Keys returns the top level keys of the current `JSON` object

func (*JSON) Map added in v0.5.1

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) MarshalJSON added in v0.5.1

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

Implements the json.Marshaler interface.

func (*JSON) Set added in v0.5.1

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 added in v0.5.1

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 added in v0.5.1

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) Uint64 added in v0.5.1

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 added in v0.5.1

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