Documentation
¶
Index ¶
- func Path(path string) []interface{}
- type JSON
- func (j JSON) Arr() []JSON
- func (j JSON) Bool() 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) 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)
fmt.Println(">", obj.JSON("> ", " "))
}
Output: 1 > { > "a": { > "b": [ > 1, > "ok" > ] > }, > "c": 2 > }
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.
Click to show internal directories.
Click to hide internal directories.