Documentation
¶
Overview ¶
Package parser parses RFC 9535 JSONPath queries into parse trees. Most JSONPath users will use package github.com/theory/jsonpath instead of this package.
inlined from: https://github.com/theory/jsonpath/blob/48554e0502cd108828c99e48ef90f56382bc7e93/spec/selector.go#L272
Index ¶
- Variables
- func Parse(reg *registry.Registry, path string) (*spec.PathQuery, error)
- type FilterSelector
- type Index
- type Name
- type Selector
- type SliceSelector
- func (s SliceSelector) Bounds(length int) (int, int)
- func (s SliceSelector) End() int
- func (s SliceSelector) Select(input, _ any) []any
- func (s SliceSelector) SelectLocated(input, _ any, parent NormalizedPath) []*LocatedNode
- func (s SliceSelector) Start() int
- func (s SliceSelector) Step() int
- func (s SliceSelector) String() string
- type WildcardSelector
Constants ¶
This section is empty.
Variables ¶
var ErrPathParse = errors.New("jsonpath")
ErrPathParse errors are returned for path parse errors.
Functions ¶
func Parse ¶
Parse parses path, a JSONPath query string, into a spec.PathQuery. Returns a ErrPathParse on parse failure.
Types ¶
type FilterSelector ¶
type FilterSelector struct {
LogicalOr
}
FilterSelector is a filter selector, e.g., ?(), as defined by RFC 9535 Section 2.3.5. Interfaces implemented:
func Filter ¶
func Filter(expr ...LogicalAnd) *FilterSelector
Filter returns a new FilterSelector that ORs the evaluation of each expr.
func (*FilterSelector) Eval ¶
func (f *FilterSelector) Eval(node, root any) bool
Eval evaluates the f's [LogicalOr] expression against node and root. Uses FilterSelector.Select as it iterates over nodes, and always passes the root value($) for filter expressions that reference it.
func (*FilterSelector) Select ¶
func (f *FilterSelector) Select(current, root any) []any
Select selects and returns values that f filters from current. Filter expressions may evaluate the current value (@), the root value ($), or any path expression. Defined by the Selector interface.
func (*FilterSelector) SelectLocated ¶
func (f *FilterSelector) SelectLocated(current, root any, parent NormalizedPath) []*LocatedNode
SelectLocated selects and returns [LocatedNode] values with values that f filters from current. Filter expressions may evaluate the current value (@), the root value ($), or any path expression. Defined by the Selector interface.
func (*FilterSelector) String ¶
func (f *FilterSelector) String() string
String returns a string representation of f.
type Index ¶
type Index int
Index is an array index selector, e.g., [3], as defined by RFC 9535 Section 2.3.3. Interfaces implemented:
- Selector
- fmt.Stringer
- [NormalSelector]
func (Index) Select ¶
Select selects i from input and returns it as a single value in a slice. Returns an empty slice if input is not a slice or if i it outside the bounds of input. Defined by the Selector interface.
func (Index) SelectLocated ¶
SelectLocated selects i from input and returns it with its normalized path as a single [LocatedNode] in a slice. Returns an empty slice if input is not a slice or if i it outside the bounds of input. Defined by the Selector interface.
type Name ¶
type Name string
Name is a key name selector, e.g., .name or ["name"], as defined by RFC 9535 Section 2.3.1. Interfaces implemented:
- Selector
- fmt.Stringer
- [NormalSelector]
func (Name) Select ¶
Select selects n from input and returns it as a single value in a slice. Returns an empty slice if input is not a map[string]any or if it does not contain n. Defined by the Selector interface.
func (Name) SelectLocated ¶
SelectLocated selects n from input and returns it with its normalized path as a single [LocatedNode] in a slice. Returns an empty slice if input is not a map[string]any or if it does not contain n. Defined by the Selector interface.
type Selector ¶
type Selector interface {
// Select selects values from current and/or root and returns them.
Select(current, root any) []any
// SelectLocated selects values from current and/or root and returns them
// in [LocatedNode] values with their located normalized paths
SelectLocated(current, root any, parent NormalizedPath) []*LocatedNode
// contains filtered or unexported methods
}
Selector represents a single Selector in an RFC 9535 JSONPath query.
type SliceSelector ¶
type SliceSelector struct {
// contains filtered or unexported fields
}
SliceSelector is a slice selector, e.g., [0:100:5], as defined by RFC 9535 Section 2.3.4. Interfaces implemented:
func Slice ¶
func Slice(args ...any) SliceSelector
Slice creates a new SliceSelector. Pass up to three integers or nils for the start, end, and step arguments. Subsequent arguments are ignored.
func (SliceSelector) Bounds ¶
func (s SliceSelector) Bounds(length int) (int, int)
Bounds returns the lower and upper bounds for selecting from a slice of length.
func (SliceSelector) Select ¶
func (s SliceSelector) Select(input, _ any) []any
Select selects and returns the values from input for the indexes specified by s. Returns an empty slice if input is not a slice. Indexes outside the bounds of input will not be included in the return value. Defined by the Selector interface.
func (SliceSelector) SelectLocated ¶
func (s SliceSelector) SelectLocated(input, _ any, parent NormalizedPath) []*LocatedNode
SelectLocated selects values from input for the indexes specified by s and returns thm with their normalized paths as [LocatedNode] values. Returns an empty slice if input is not a slice. Indexes outside the bounds of input will not be included in the return value. Defined by the Selector interface.
func (SliceSelector) String ¶
func (s SliceSelector) String() string
String returns a quoted string representation of s.
type WildcardSelector ¶
type WildcardSelector struct{}
WildcardSelector is a wildcard selector, e.g., * or [*], as defined by RFC 9535 Section 2.3.2. Interfaces implemented:
func (WildcardSelector) Select ¶
func (WildcardSelector) Select(input, _ any) []any
Select selects the values from input and returns them in a slice. Returns an empty slice if input is not []any map[string]any. Defined by the Selector interface.
func (WildcardSelector) SelectLocated ¶
func (WildcardSelector) SelectLocated(input, _ any, parent NormalizedPath) []*LocatedNode
SelectLocated selects the values from input and returns them with their normalized paths in a slice of [LocatedNode] values. Returns an empty slice if input is not []any map[string]any. Defined by the Selector interface.