Documentation ¶
Overview ¶
Package gson A tiny JSON lib to read and alter a JSON value.
Index ¶
- func Bool(v bool) *bool
- func Int(v int) *int
- func Num(v float64) *float64
- func Path(path string) []interface{}
- func Str(v string) *string
- type JSON
- func (j JSON) Arr() []JSON
- func (j JSON) Bool() bool
- func (j *JSON) Del(path string) *JSON
- func (j *JSON) Dels(sections ...interface{}) bool
- func (j JSON) Get(path string) JSON
- func (j JSON) Gets(sections ...interface{}) (JSON, bool)
- func (j JSON) Has(path string) bool
- func (j JSON) Int() int
- func (j JSON) JSON(prefix, indent string) string
- func (j JSON) Join(sep string) string
- func (j JSON) Map() map[string]JSON
- func (j JSON) MarshalJSON() ([]byte, error)
- func (j JSON) Nil() bool
- func (j JSON) Num() float64
- func (j JSON) Raw() interface{}
- func (j *JSON) Set(path string, val interface{}) *JSON
- func (j *JSON) Sets(target interface{}, sections ...interface{}) *JSON
- func (j JSON) Str() string
- func (j JSON) String() string
- func (j JSON) Unmarshal(v interface{}) error
- func (j *JSON) UnmarshalJSON(b []byte) error
- func (j JSON) Val() interface{}
- type Query
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type JSON ¶
type JSON struct {
// contains filtered or unexported fields
}
JSON represent a JSON value
Example ¶
package main import ( "fmt" "github.com/ysmood/gson" ) func main() { obj := gson.NewFrom(`{"a": {"b": [1, 2]}}`) fmt.Println(obj.Get("a.b.0").Int()) obj.Set("a.b.1", "ok").Set("c", 2) obj.Del("c") fmt.Println(">", obj.JSON("> ", " ")) }
Output: 1 > { > "a": { > "b": [ > 1, > "ok" > ] > } > }
func (*JSON) Dels ¶ added in v0.7.0
Dels deletes the element at the path sections. Return true if it's deleted.
func (JSON) Gets ¶
Gets element by path sections. If a section is not string, int, or func, it will be ignored. If it's a func, the value will be passed to it, the result of it will the next level. The last return value will be false if not found.
func (*JSON) Sets ¶
Sets element by path sections. If a section is not string or int, it will be ignored.
func (JSON) Unmarshal ¶ added in v0.7.3
Unmarshal is the same as json.Unmarshal for the underlying raw value. It should be called before other operations.
Click to show internal directories.
Click to hide internal directories.