-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjpath.go
More file actions
36 lines (30 loc) · 961 Bytes
/
Copy pathjpath.go
File metadata and controls
36 lines (30 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package jpath
// Parse parses a JSONPath query into a PathExpr syntax tree
func Parse(query string) (*PathExpr, error) {
var p Parser
return p.Parse(query)
}
// MustParse parses a JSONPath query or panics
func MustParse(query string) *PathExpr {
path, err := Parse(query)
if err != nil {
panic(err)
}
return path
}
// Compile compiles a parsed PathExpr into an executable Path
func Compile(path *PathExpr) (Path, error) {
return NewRegistry().Compile(path)
}
// MustCompile compiles a parsed PathExpr or panics
func MustCompile(path *PathExpr) Path {
return NewRegistry().MustCompile(path)
}
// Query parses and compiles a JSONPath query, then runs it on a document
func Query(query string, document any) ([]any, error) {
return NewRegistry().Query(query, document)
}
// MustQuery parses and compiles a JSONPath query, then runs it or panics
func MustQuery(query string, document any) []any {
return NewRegistry().MustQuery(query, document)
}