Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue when filtering nested array #2

Merged
merged 5 commits into from
Apr 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: ci
on: push
pradithya marked this conversation as resolved.
Show resolved Hide resolved
jobs:
test:
runs-on: ubuntu-latest
name: Go ${{ matrix.go }} test
strategy:
matrix:
go: ["1.16", "1.17"]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-go@v2
with:
go-version: ${{ matrix.go }}
- run: go test -v ./...
10 changes: 5 additions & 5 deletions jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (c *Compiled) Lookup(obj interface{}) (interface{}, error) {
case "range":
if len(s.key) > 0 {
// no key `$[:1].test`
obj, err = get_key_with_flatening(obj, s.key, true)
obj, err = get_key_with_flattening(obj, s.key, true)
if err != nil {
return nil, err
}
Expand All @@ -127,7 +127,7 @@ func (c *Compiled) Lookup(obj interface{}) (interface{}, error) {
return nil, fmt.Errorf("range args length should be 2")
}
case "filter":
obj, err = get_key_with_flatening(obj, s.key, true)
obj, err = get_key_with_flattening(obj, s.key, true)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -325,7 +325,7 @@ func filter_get_from_explicit_path(obj interface{}, path string) (interface{}, e
return xobj, nil
}

func get_key_with_flatening(obj interface{}, key string, isFlaten bool) (interface{}, error) {
func get_key_with_flattening(obj interface{}, key string, isFlatten bool) (interface{}, error) {
if reflect.TypeOf(obj) == nil {
return nil, nil
}
Expand Down Expand Up @@ -356,7 +356,7 @@ func get_key_with_flatening(obj interface{}, key string, isFlaten bool) (interfa
if v, err := get_key(tmp, key); err == nil {
keyVal := reflect.ValueOf(v)
// flatten the value is the result is array or slice
if keyVal.Kind() == reflect.Slice && isFlaten {
if keyVal.Kind() == reflect.Slice && isFlatten {
for j := 0; j < keyVal.Len(); j++ {
res = append(res, keyVal.Index(j).Interface())
}
Expand All @@ -372,7 +372,7 @@ func get_key_with_flatening(obj interface{}, key string, isFlaten bool) (interfa
}

func get_key(obj interface{}, key string) (interface{}, error) {
return get_key_with_flatening(obj, key, false)
return get_key_with_flattening(obj, key, false)
}

func get_idx(obj interface{}, idx int) (interface{}, error) {
Expand Down