gjson

package
v1.11.3 Latest Latest
Warning

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

Go to latest
Published: Jan 16, 2020 License: MIT Imports: 21 Imported by: 144

Documentation

Overview

Package gjson provides convenient API for JSON/XML/YAML/TOML data handling.

Package gjson provides convenient API for JSON/XML/YAML/TOML data handling.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Decode

func Decode(data interface{}) (interface{}, error)

Decode decodes <data>(string/[]byte) to golang variable.

func DecodeTo

func DecodeTo(data interface{}, v interface{}) error

Decode decodes <data>(string/[]byte) to specified golang variable <v>. The <v> should be a pointer type.

func Encode

func Encode(value interface{}) ([]byte, error)

Encode encodes <value> to JSON data type of bytes.

func Valid

func Valid(data interface{}) bool

Valid checks whether <data> is a valid JSON data type.

Types

type Json

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

The customized JSON struct.

func DecodeToJson

func DecodeToJson(data interface{}, safe ...bool) (*Json, error)

DecodeToJson codes <data>(string/[]byte) to a Json object.

func Load

func Load(path string, safe ...bool) (*Json, error)

Load loads content from specified file <path>, and creates a Json object from its content.

func LoadContent

func LoadContent(data interface{}, safe ...bool) (*Json, error)

func LoadIni

func LoadIni(data interface{}, safe ...bool) (*Json, error)

func LoadJson

func LoadJson(data interface{}, safe ...bool) (*Json, error)

func LoadToml

func LoadToml(data interface{}, safe ...bool) (*Json, error)

func LoadXml

func LoadXml(data interface{}, safe ...bool) (*Json, error)

func LoadYaml

func LoadYaml(data interface{}, safe ...bool) (*Json, error)

func New

func New(data interface{}, safe ...bool) *Json

New creates a Json object with any variable type of <data>, but <data> should be a map or slice for data access reason, or it will make no sense. The <safe> param specifies whether using this Json object in concurrent-safe context, which is false in default.

func (*Json) Append

func (j *Json) Append(pattern string, value interface{}) error

Append appends value to the value by specified <pattern>. The target value by <pattern> should be type of slice.

func (*Json) Contains

func (j *Json) Contains(pattern string) bool

Contains checks whether the value by specified <pattern> exist.

func (*Json) Dump

func (j *Json) Dump()

Dump prints current Json object with more manually readable.

func (*Json) Export

func (j *Json) Export() string

Export returns <j> as a string with more manually readable.

func (*Json) Get

func (j *Json) Get(pattern string, def ...interface{}) interface{}

Get returns value by specified <pattern>. It returns all values of current Json object, if <pattern> is empty or not specified. It returns nil if no value found by <pattern>.

We can also access slice item by its index number in <pattern>, eg: "items.name.first", "list.10".

It returns a default value specified by <def> if value for <pattern> is not found.

func (*Json) GetArray

func (j *Json) GetArray(pattern string, def ...interface{}) []interface{}

GetArray gets the value by specified <pattern>, and converts it to a slice of []interface{}.

func (*Json) GetBool

func (j *Json) GetBool(pattern string, def ...interface{}) bool

GetBool gets the value by specified <pattern>, and converts it to bool. It returns false when value is: "", 0, false, off, nil; or returns true instead.

func (*Json) GetBytes

func (j *Json) GetBytes(pattern string, def ...interface{}) []byte

func (*Json) GetDuration

func (j *Json) GetDuration(pattern string, def ...interface{}) time.Duration

func (*Json) GetFloat32

func (j *Json) GetFloat32(pattern string, def ...interface{}) float32

func (*Json) GetFloat64

func (j *Json) GetFloat64(pattern string, def ...interface{}) float64

func (*Json) GetFloats

func (j *Json) GetFloats(pattern string, def ...interface{}) []float64

func (*Json) GetGTime

func (j *Json) GetGTime(pattern string, format ...string) *gtime.Time

func (*Json) GetInt

func (j *Json) GetInt(pattern string, def ...interface{}) int

func (*Json) GetInt16

func (j *Json) GetInt16(pattern string, def ...interface{}) int16

func (*Json) GetInt32

func (j *Json) GetInt32(pattern string, def ...interface{}) int32

func (*Json) GetInt64

func (j *Json) GetInt64(pattern string, def ...interface{}) int64

func (*Json) GetInt8

func (j *Json) GetInt8(pattern string, def ...interface{}) int8

func (*Json) GetInterfaces

func (j *Json) GetInterfaces(pattern string, def ...interface{}) []interface{}

See GetArray.

func (*Json) GetInts

func (j *Json) GetInts(pattern string, def ...interface{}) []int

func (*Json) GetJson

func (j *Json) GetJson(pattern string, def ...interface{}) *Json

GetJson gets the value by specified <pattern>, and converts it to a un-concurrent-safe Json object.

func (*Json) GetJsonMap

func (j *Json) GetJsonMap(pattern string, def ...interface{}) map[string]*Json

GetJsonMap gets the value by specified <pattern>, and converts it to a map of un-concurrent-safe Json object.

func (*Json) GetJsons

func (j *Json) GetJsons(pattern string, def ...interface{}) []*Json

GetJsons gets the value by specified <pattern>, and converts it to a slice of un-concurrent-safe Json object.

func (*Json) GetMap

func (j *Json) GetMap(pattern string, def ...interface{}) map[string]interface{}

GetMap retrieves the value by specified <pattern>, and converts it to map[string]interface{}.

func (*Json) GetMapStrStr added in v1.10.1

func (j *Json) GetMapStrStr(pattern string, def ...interface{}) map[string]string

GetMapStrStr retrieves the value by specified <pattern>, and converts it to map[string]string.

func (*Json) GetMapToMap added in v1.9.3

func (j *Json) GetMapToMap(pattern string, pointer interface{}, mapping ...map[string]string) error

func (*Json) GetMapToMapDeep added in v1.9.3

func (j *Json) GetMapToMapDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

func (*Json) GetMapToMaps added in v1.9.3

func (j *Json) GetMapToMaps(pattern string, pointer interface{}, mapping ...map[string]string) error

func (*Json) GetMapToMapsDeep added in v1.9.3

func (j *Json) GetMapToMapsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

func (*Json) GetString

func (j *Json) GetString(pattern string, def ...interface{}) string

GetString gets the value by specified <pattern>, and converts it to string.

func (*Json) GetStrings

func (j *Json) GetStrings(pattern string, def ...interface{}) []string

GetStrings gets the value by specified <pattern>, and converts it to a slice of []string.

func (*Json) GetStruct

func (j *Json) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStruct gets the value by specified <pattern>, and converts it to specified object <pointer>. The <pointer> should be the pointer to an object.

func (*Json) GetStructDeep

func (j *Json) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructDeep does GetStruct recursively.

func (*Json) GetStructs

func (j *Json) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructs converts any slice to given struct slice.

func (*Json) GetStructsDeep

func (j *Json) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error

GetStructsDeep converts any slice to given struct slice recursively.

func (*Json) GetTime

func (j *Json) GetTime(pattern string, format ...string) time.Time

func (*Json) GetUint

func (j *Json) GetUint(pattern string, def ...interface{}) uint

func (*Json) GetUint16

func (j *Json) GetUint16(pattern string, def ...interface{}) uint16

func (*Json) GetUint32

func (j *Json) GetUint32(pattern string, def ...interface{}) uint32

func (*Json) GetUint64

func (j *Json) GetUint64(pattern string, def ...interface{}) uint64

func (*Json) GetUint8

func (j *Json) GetUint8(pattern string, def ...interface{}) uint8

func (*Json) GetVar

func (j *Json) GetVar(pattern string, def ...interface{}) *gvar.Var

GetVar returns a *gvar.Var with value by given <pattern>.

func (*Json) GetVars

func (j *Json) GetVars(pattern string, def ...interface{}) []*gvar.Var

GetVars returns []*gvar.Var with value by given <pattern>.

func (*Json) IsNil

func (j *Json) IsNil() bool

IsNil checks whether the value pointed by <j> is nil.

func (*Json) Len

func (j *Json) Len(pattern string) int

Len returns the length/size of the value by specified <pattern>. The target value by <pattern> should be type of slice or map. It returns -1 if the target value is not found, or its type is invalid.

func (*Json) MarshalJSON

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

MarshalJSON implements the interface MarshalJSON for json.Marshal.

func (*Json) MustToIni added in v1.10.1

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

func (*Json) MustToIniString added in v1.10.1

func (j *Json) MustToIniString() string

func (*Json) MustToJson added in v1.10.1

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

func (*Json) MustToJsonIndent added in v1.10.1

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

func (*Json) MustToJsonIndentString added in v1.10.1

func (j *Json) MustToJsonIndentString() string

func (*Json) MustToJsonString added in v1.10.1

func (j *Json) MustToJsonString() string

func (*Json) MustToToml added in v1.10.1

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

func (*Json) MustToTomlString added in v1.10.1

func (j *Json) MustToTomlString() string

func (*Json) MustToXml added in v1.10.1

func (j *Json) MustToXml(rootTag ...string) []byte

func (*Json) MustToXmlIndent added in v1.10.1

func (j *Json) MustToXmlIndent(rootTag ...string) []byte

func (*Json) MustToXmlIndentString added in v1.10.1

func (j *Json) MustToXmlIndentString(rootTag ...string) string

func (*Json) MustToXmlString added in v1.10.1

func (j *Json) MustToXmlString(rootTag ...string) string

func (*Json) MustToYaml added in v1.10.1

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

func (*Json) MustToYamlString added in v1.10.1

func (j *Json) MustToYamlString() string

func (*Json) Remove

func (j *Json) Remove(pattern string) error

Remove deletes value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.

func (*Json) Set

func (j *Json) Set(pattern string, value interface{}) error

Set sets value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.

func (*Json) SetSplitChar

func (j *Json) SetSplitChar(char byte)

SetSplitChar sets the separator char for hierarchical data access.

func (*Json) SetViolenceCheck

func (j *Json) SetViolenceCheck(enabled bool)

SetViolenceCheck enables/disables violence check for hierarchical data access.

func (*Json) ToArray

func (j *Json) ToArray() []interface{}

ToArray converts current Json object to []interface{}. It returns nil if fails.

func (*Json) ToIni

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

func (*Json) ToIniString

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

func (*Json) ToJson

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

func (*Json) ToJsonIndent

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

func (*Json) ToJsonIndentString

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

func (*Json) ToJsonString

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

func (*Json) ToMap

func (j *Json) ToMap() map[string]interface{}

ToMap converts current Json object to map[string]interface{}. It returns nil if fails.

func (*Json) ToMapToMap added in v1.9.3

func (j *Json) ToMapToMap(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToMapToMapDeep added in v1.9.3

func (j *Json) ToMapToMapDeep(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToMapToMaps added in v1.9.3

func (j *Json) ToMapToMaps(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToMapToMapsDeep added in v1.9.3

func (j *Json) ToMapToMapsDeep(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToStruct

func (j *Json) ToStruct(pointer interface{}, mapping ...map[string]string) error

ToStruct converts current Json object to specified object. The <pointer> should be a pointer type.

func (*Json) ToStructDeep

func (j *Json) ToStructDeep(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToStructs

func (j *Json) ToStructs(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToStructsDeep

func (j *Json) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error

func (*Json) ToToml

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

func (*Json) ToTomlString

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

func (*Json) ToXml

func (j *Json) ToXml(rootTag ...string) ([]byte, error)

func (*Json) ToXmlIndent

func (j *Json) ToXmlIndent(rootTag ...string) ([]byte, error)

func (*Json) ToXmlIndentString

func (j *Json) ToXmlIndentString(rootTag ...string) (string, error)

func (*Json) ToXmlString

func (j *Json) ToXmlString(rootTag ...string) (string, error)

func (*Json) ToYaml

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

func (*Json) ToYamlString

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

func (*Json) Value

func (j *Json) Value() interface{}

Val returns the json value.

Jump to

Keyboard shortcuts

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