gf: github.com/johng-cn/gf/g/encoding/gjson Index | Files

package gjson

import "github.com/johng-cn/gf/g/encoding/gjson"

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

Package Files

gjson.go gjson_api.go gjson_api_config.go gjson_api_encoding.go gjson_api_new_load.go gjson_func.go

func Decode Uses

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

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

func DecodeTo Uses

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 Uses

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

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

func Valid Uses

func Valid(data interface{}) bool

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

type Json Uses

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

The customized JSON struct.

func DecodeToJson Uses

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

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

func Load Uses

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

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

func LoadContent Uses

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

LoadContent creates a Json object from given content, it checks the data type of <content> automatically, supporting JSON, XML, YAML and TOML types of data.

func New Uses

func New(data interface{}, unsafe ...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 <unsafe> param specifies whether using this Json object in un-concurrent-safe context, which is false in default.

func NewUnsafe Uses

func NewUnsafe(data ...interface{}) *Json

NewUnsafe creates a un-concurrent-safe Json object.

func (*Json) Append Uses

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 Uses

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

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

func (*Json) Dump Uses

func (j *Json) Dump() error

Dump prints current Json object with more manually readable.

func (*Json) Get Uses

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 Uses

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 Uses

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) GetDuration Uses

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

func (*Json) GetFloat32 Uses

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

func (*Json) GetFloat64 Uses

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

func (*Json) GetFloats Uses

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

func (*Json) GetGTime Uses

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

func (*Json) GetInt Uses

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

func (*Json) GetInt16 Uses

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

func (*Json) GetInt32 Uses

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

func (*Json) GetInt64 Uses

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

func (*Json) GetInt8 Uses

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

func (*Json) GetInterfaces Uses

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

See GetArray.

func (*Json) GetInts Uses

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

func (*Json) GetJson Uses

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 Uses

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 Uses

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 Uses

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

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

func (*Json) GetString Uses

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

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

func (*Json) GetStrings Uses

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) GetTime Uses

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

func (*Json) GetToStruct Uses

func (j *Json) GetToStruct(pattern string, pointer interface{}) error

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

func (*Json) GetToVar Uses

func (j *Json) GetToVar(pattern string, pointer interface{}) error

GetToVar gets the value by specified <pattern>, and converts it to specified golang variable <v>. The <pointer> should be a pointer type.

func (*Json) GetUint Uses

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

func (*Json) GetUint16 Uses

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

func (*Json) GetUint32 Uses

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

func (*Json) GetUint64 Uses

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

func (*Json) GetUint8 Uses

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

func (*Json) GetVar Uses

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

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

func (*Json) Len Uses

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) Remove Uses

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 Uses

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 Uses

func (j *Json) SetSplitChar(char byte)

SetSplitChar sets the separator char for hierarchical data access.

func (*Json) SetViolenceCheck Uses

func (j *Json) SetViolenceCheck(enabled bool)

SetViolenceCheck enables/disables violence check for hierarchical data access.

func (*Json) ToArray Uses

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

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

func (*Json) ToJson Uses

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

func (*Json) ToJsonIndent Uses

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

func (*Json) ToJsonIndentString Uses

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

func (*Json) ToJsonString Uses

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

func (*Json) ToMap Uses

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

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

func (*Json) ToStruct Uses

func (j *Json) ToStruct(pointer interface{}) error

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

func (*Json) ToToml Uses

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

func (*Json) ToTomlString Uses

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

func (*Json) ToXml Uses

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

func (*Json) ToXmlIndent Uses

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

func (*Json) ToXmlIndentString Uses

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

func (*Json) ToXmlString Uses

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

func (*Json) ToYaml Uses

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

func (*Json) ToYamlString Uses

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

func (*Json) Value Uses

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

Val returns the json value.

Package gjson imports 18 packages (graph). Updated 2019-06-19. Refresh now. Tools for package owners.