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) []any
- 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 ...any) bool
- func (j JSON) Get(path string) JSON
- func (j JSON) Gets(sections ...any) (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() any
- func (j *JSON) Set(path string, val any) *JSON
- func (j *JSON) Sets(target any, sections ...any) *JSON
- func (j JSON) Str() string
- func (j JSON) String() string
- func (j JSON) Unmarshal(v any) error
- func (j *JSON) UnmarshalJSON(b []byte) error
- func (j JSON) Val() any
- 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/runZeroInc/go-rod/pkg/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) 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 ¶
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.