Documentation ¶
Index ¶
- func Find(node Node, path gojsonpath.Path) ([]any, error)
- func ParseAndFind(node Node, path string) ([]any, error)
- func Search(node Node, path gojsonpath.Path, capture func(gojsonpath.DocPath)) error
- type Array
- func (a *Array) Append(values ...Node)
- func (a *Array) Clear()
- func (a *Array) Each(f func(int, Node) bool) bool
- func (a *Array) Encode(w io.Writer) error
- func (a *Array) Len() int
- func (a *Array) Marshal() interface{}
- func (a *Array) MarshalJSON() ([]byte, error)
- func (a *Array) N(index int) Node
- func (a *Array) Remove(index int)
- func (a *Array) Set(index int, value Node)
- type KeyValue
- type MapInterner
- type Node
- type Object
- func (o *Object) AddOrSet(kv *KeyValue) bool
- func (o *Object) Clear()
- func (o *Object) Each(f func(*KeyValue) bool) bool
- func (o *Object) Encode(w io.Writer) error
- func (o *Object) Get(key string) *KeyValue
- func (o *Object) Len() int
- func (o *Object) Marshal() interface{}
- func (o *Object) MarshalJSON() ([]byte, error)
- func (o *Object) N(index int) *KeyValue
- func (o *Object) Remove(key string) bool
- func (o *Object) Set(key string, value Node) bool
- func (o *Object) Value(key string) (Node, bool)
- type PathModel
- type StringInterner
- type Value
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ParseAndFind ¶ added in v1.2.0
ParseAndFind parses the path and finds matching nodes in the doc
func Search ¶ added in v1.2.0
func Search(node Node, path gojsonpath.Path, capture func(gojsonpath.DocPath)) error
Search iterates all document nodes depth-first, and calls `capture` for those document nodes that `path` matches.
Types ¶
type Array ¶
type Array struct {
// contains filtered or unexported fields
}
Array represents a JSON array
func (*Array) Marshal ¶
func (a *Array) Marshal() interface{}
Marshal returns a []interface{} for the array, where each element is recursively marshaled
func (*Array) MarshalJSON ¶
MarshalJSON allows using json.Marshal for an array node
type KeyValue ¶
type KeyValue struct {
// contains filtered or unexported fields
}
KeyValue represents a JSON key-value pair in an Object
func NewKeyValue ¶
NewKeyValue returns a new key-value pair
type MapInterner ¶
type MapInterner struct {
// contains filtered or unexported fields
}
MapInterner uses a map to keep single copies of strings. Empty value of DefaultInterner is ready to use
func (*MapInterner) Intern ¶
func (interner *MapInterner) Intern(s string) string
Intern updates the internal string table to include the given string
type Node ¶
type Node interface { // Marshal a node to one of: map[string]interface{}, []interface{}, // or one of the JSON value types: nil, string, bool, or json.Number Marshal() interface{} // Encode the node into a JSON document Encode(io.Writer) error // contains filtered or unexported methods }
Node is a node in a JSON object model
func Decode ¶
func Decode(decoder *json.Decoder, interner StringInterner) (Node, error)
Decode a JSON object using the given decoder. Interner is optional, it will be used if given. If omitted, an internal temporary interner will be used.
func Unmarshal ¶
func Unmarshal(input []byte, interner StringInterner) (Node, error)
Unmarshal the given byte slice to a json object model node
func UnmarshalIntf ¶
UnmarshalIntf creates a JSON object model from a tree of objects, as output from json.Marshal
func UnmarshalReader ¶
func UnmarshalReader(input io.Reader, interner StringInterner) (Node, error)
UnmarshalReader unmarshals the input to a json object model node
type Object ¶
type Object struct {
// contains filtered or unexported fields
}
Object represents a JSON object, an ordered set of key-value pairs. The zero-value of an Object is ready to use
func (*Object) AddOrSet ¶
AddOrSet adds a key-value pair if the key does not exist in this object, or replaces an existing key-value pair with the given one. Returns true if the key is added, false if it is updated
func (*Object) Get ¶
Get returns a key-value pair by its key. If the key does not exist, returns nil
func (*Object) Marshal ¶
func (o *Object) Marshal() interface{}
Marshal returns a map[string]interface{} for the object where each value is recursively marshaled. This operation loses the ordering of the object elements.
func (*Object) MarshalJSON ¶
MarshalJSON allows using json.Marshal for an object node
func (*Object) Remove ¶
Remove a key from the object. Returns true if the key was in the object, and removed
type PathModel ¶ added in v1.2.0
type PathModel struct {
Node
}
PathModel is the adapter for Node to use in JSON Path lookups
type StringInterner ¶
StringInterner is used to reduce the memory footprint of a json document by interning the keys, so the same copy of string is used throughout the file
type Value ¶
type Value struct {
// contains filtered or unexported fields
}
A Value is one of: nil, string, bool, json.Number
func NewValue ¶
func NewValue(value interface{}) *Value
NewValue returns a new value. The value must be convertible to one of: nil, string, bool, or json.Number
func StringValue ¶
StringValue creates a new Value from a string
func (Value) MarshalJSON ¶
MarshalJSON allows using json.Marshal for a value node