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 ¶
- func Decode(data interface{}) (interface{}, error)
- func DecodeTo(data interface{}, v interface{}) error
- func Encode(value interface{}) ([]byte, error)
- func Valid(data interface{}) bool
- type Json
- func DecodeToJson(data interface{}, safe ...bool) (*Json, error)
- func Load(path string, safe ...bool) (*Json, error)
- func LoadContent(data interface{}, safe ...bool) (*Json, error)
- func LoadIni(data interface{}, safe ...bool) (*Json, error)
- func LoadJson(data interface{}, safe ...bool) (*Json, error)
- func LoadToml(data interface{}, safe ...bool) (*Json, error)
- func LoadXml(data interface{}, safe ...bool) (*Json, error)
- func LoadYaml(data interface{}, safe ...bool) (*Json, error)
- func New(data interface{}, safe ...bool) *Json
- func (j *Json) Append(pattern string, value interface{}) error
- func (j *Json) Contains(pattern string) bool
- func (j *Json) Dump()
- func (j *Json) Export() string
- func (j *Json) Get(pattern string, def ...interface{}) interface{}
- func (j *Json) GetArray(pattern string, def ...interface{}) []interface{}
- func (j *Json) GetBool(pattern string, def ...interface{}) bool
- func (j *Json) GetBytes(pattern string, def ...interface{}) []byte
- func (j *Json) GetDuration(pattern string, def ...interface{}) time.Duration
- func (j *Json) GetFloat32(pattern string, def ...interface{}) float32
- func (j *Json) GetFloat64(pattern string, def ...interface{}) float64
- func (j *Json) GetFloats(pattern string, def ...interface{}) []float64
- func (j *Json) GetGTime(pattern string, format ...string) *gtime.Time
- func (j *Json) GetInt(pattern string, def ...interface{}) int
- func (j *Json) GetInt16(pattern string, def ...interface{}) int16
- func (j *Json) GetInt32(pattern string, def ...interface{}) int32
- func (j *Json) GetInt64(pattern string, def ...interface{}) int64
- func (j *Json) GetInt8(pattern string, def ...interface{}) int8
- func (j *Json) GetInterfaces(pattern string, def ...interface{}) []interface{}
- func (j *Json) GetInts(pattern string, def ...interface{}) []int
- func (j *Json) GetJson(pattern string, def ...interface{}) *Json
- func (j *Json) GetJsonMap(pattern string, def ...interface{}) map[string]*Json
- func (j *Json) GetJsons(pattern string, def ...interface{}) []*Json
- func (j *Json) GetMap(pattern string, def ...interface{}) map[string]interface{}
- func (j *Json) GetMapStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetMapStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetMapStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetMapStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetString(pattern string, def ...interface{}) string
- func (j *Json) GetStrings(pattern string, def ...interface{}) []string
- func (j *Json) GetStruct(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetStructDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetStructs(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetStructsDeep(pattern string, pointer interface{}, mapping ...map[string]string) error
- func (j *Json) GetTime(pattern string, format ...string) time.Time
- func (j *Json) GetUint(pattern string, def ...interface{}) uint
- func (j *Json) GetUint16(pattern string, def ...interface{}) uint16
- func (j *Json) GetUint32(pattern string, def ...interface{}) uint32
- func (j *Json) GetUint64(pattern string, def ...interface{}) uint64
- func (j *Json) GetUint8(pattern string, def ...interface{}) uint8
- func (j *Json) GetVar(pattern string, def ...interface{}) *gvar.Var
- func (j *Json) GetVars(pattern string, def ...interface{}) []*gvar.Var
- func (j *Json) IsNil() bool
- func (j *Json) Len(pattern string) int
- func (j *Json) MarshalJSON() ([]byte, error)
- func (j *Json) Remove(pattern string) error
- func (j *Json) Set(pattern string, value interface{}) error
- func (j *Json) SetSplitChar(char byte)
- func (j *Json) SetViolenceCheck(enabled bool)
- func (j *Json) ToArray() []interface{}
- func (j *Json) ToIni() ([]byte, error)
- func (j *Json) ToIniString() (string, error)
- func (j *Json) ToJson() ([]byte, error)
- func (j *Json) ToJsonIndent() ([]byte, error)
- func (j *Json) ToJsonIndentString() (string, error)
- func (j *Json) ToJsonString() (string, error)
- func (j *Json) ToMap() map[string]interface{}
- func (j *Json) ToMapStruct(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToMapStructDeep(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToMapStructs(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToMapStructsDeep(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToStruct(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToStructDeep(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToStructs(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToStructsDeep(pointer interface{}, mapping ...map[string]string) error
- func (j *Json) ToToml() ([]byte, error)
- func (j *Json) ToTomlString() (string, error)
- func (j *Json) ToXml(rootTag ...string) ([]byte, error)
- func (j *Json) ToXmlIndent(rootTag ...string) ([]byte, error)
- func (j *Json) ToXmlIndentString(rootTag ...string) (string, error)
- func (j *Json) ToXmlString(rootTag ...string) (string, error)
- func (j *Json) ToYaml() ([]byte, error)
- func (j *Json) ToYamlString() (string, error)
- func (j *Json) Value() interface{}
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 ¶
Encode encodes <value> to JSON data type of bytes.
Types ¶
type Json ¶
type Json struct {
// contains filtered or unexported fields
}
The customized JSON struct.
func DecodeToJson ¶
DecodeToJson codes <data>(string/[]byte) to a Json object.
func Load ¶
Load loads content from specified file <path>, and creates a Json object from its content.
func New ¶
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 (*Json) Append ¶
Append appends value to the value by specified <pattern>. The target value by <pattern> should be type of slice.
func (*Json) Contains ¶
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 ¶
Export returns <j> as a string with more manually readable.
func (*Json) Get ¶
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 ¶
GetArray gets the value by specified <pattern>, and converts it to a slice of []interface{}.
func (*Json) GetBool ¶
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 ¶
func (*Json) GetInterfaces ¶
See GetArray.
func (*Json) GetJson ¶
GetJson gets the value by specified <pattern>, and converts it to a un-concurrent-safe Json object.
func (*Json) GetJsonMap ¶
GetJsonMap gets the value by specified <pattern>, and converts it to a map of un-concurrent-safe Json object.
func (*Json) GetJsons ¶
GetJsons gets the value by specified <pattern>, and converts it to a slice of un-concurrent-safe Json object.
func (*Json) GetMap ¶
GetMap gets the value by specified <pattern>, and converts it to map[string]interface{}.
func (*Json) GetMapStruct ¶
func (*Json) GetMapStructDeep ¶
func (*Json) GetMapStructs ¶
func (*Json) GetMapStructsDeep ¶
func (*Json) GetString ¶
GetString gets the value by specified <pattern>, and converts it to string.
func (*Json) GetStrings ¶
GetStrings gets the value by specified <pattern>, and converts it to a slice of []string.
func (*Json) GetStruct ¶
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 ¶
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) GetVar ¶
GetVar returns a *gvar.Var with value by given <pattern>.
func (*Json) GetVars ¶
GetVars returns []*gvar.Var with value by given <pattern>.
func (*Json) IsNil ¶
IsNil checks whether the value pointed by <j> is nil.
func (*Json) Len ¶
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 ¶
MarshalJSON implements the interface MarshalJSON for json.Marshal.
func (*Json) Remove ¶
Remove deletes value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.
func (*Json) Set ¶
Set sets value with specified <pattern>. It supports hierarchical data access by char separator, which is '.' in default.
func (*Json) SetSplitChar ¶
SetSplitChar sets the separator char for hierarchical data access.
func (*Json) SetViolenceCheck ¶
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) ToMap ¶
ToMap converts current Json object to map[string]interface{}. It returns nil if fails.
func (*Json) ToMapStruct ¶
func (*Json) ToMapStructDeep ¶
func (*Json) ToMapStructs ¶
func (*Json) ToMapStructsDeep ¶
func (*Json) ToStruct ¶
ToStruct converts current Json object to specified object. The <pointer> should be a pointer type.