https://github.com/aaronland/go-json-query
Go package for querying and filter JSON documents using tidwall/gjson-style paths and regular expressions for testing values.
https://github.com/aaronland/go-json-query
golang json
Last synced: 4 months ago
JSON representation
Go package for querying and filter JSON documents using tidwall/gjson-style paths and regular expressions for testing values.
- Host: GitHub
- URL: https://github.com/aaronland/go-json-query
- Owner: aaronland
- License: bsd-3-clause
- Created: 2020-07-11T17:36:48.000Z (almost 6 years ago)
- Default Branch: main
- Last Pushed: 2025-04-08T00:34:34.000Z (over 1 year ago)
- Last Synced: 2025-05-27T19:08:40.423Z (about 1 year ago)
- Topics: golang, json
- Language: Go
- Homepage:
- Size: 104 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go-json-query
Go package for querying and filter JSON documents using tidwall/gjson-style paths and regular expressions for testing values.
## Documentation
[](https://pkg.go.dev/github.com/aaronland/go-json-query)
## Important
Documentation is incomplete.
## Example
```
import (
"context"
"flag"
"fmt"
"github.com/aaronland/go-json-query"
"io"
"os"
"strings"
)
func main() {
var queries query.QueryFlags
flag.Var(&queries, "query", "One or more {PATH}={REGEXP} parameters for filtering records.")
valid_modes := strings.Join([]string{query.QUERYSET_MODE_ALL, query.QUERYSET_MODE_ANY}, ", ")
desc_modes := fmt.Sprintf("Specify how query filtering should be evaluated. Valid modes are: %s", valid_modes)
query_mode := flag.String("query-mode", query.QUERYSET_MODE_ALL, desc_modes)
flag.Parse()
paths := flag.Args()
qs := &query.QuerySet{
Queries: queries,
Mode: *query_mode,
}
ctx := context.Background()
for _, path := range paths {
fh, _ := os.Open(path)
defer fh.Close()
body, _ := io.ReadAll(fh)
matches, _ := query.Matches(ctx, qs, body)
fmt.Printf("%s\t%t\n", path, matches)
}
}
```
## See also
* https://github.com/tidwall/gjson