From eb9e27db8a7f431570d086aca325c39b9a7d8dec Mon Sep 17 00:00:00 2001 From: Tarun Lalwani Date: Sun, 6 Dec 2020 16:08:33 +0530 Subject: [PATCH] Allow json path to work in objects which are struct based interfaces --- selector.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/selector.go b/selector.go index 46670c2..13aa68d 100644 --- a/selector.go +++ b/selector.go @@ -3,9 +3,9 @@ package jsonpath import ( "context" "fmt" - "strconv" - "github.com/PaesslerAG/gval" + "reflect" + "strconv" ) //plainSelector evaluate exactly one result @@ -116,10 +116,19 @@ func visitAll(v interface{}, visit func(key string, v interface{})) { for k, e := range v { visit(k, e) } + case interface{}: + vo := reflect.ValueOf(v) + if vo.Kind() == reflect.Map { + for _, vok := range vo.MapKeys() { + if vok.Kind() == reflect.String || vok.Kind() == reflect.Int { + visit(vok.String(), vo.MapIndex(vok).Interface()) + } + } + } } - } + //[? ] func filterSelector(filter gval.Evaluable) ambiguousSelector { return func(c context.Context, r, v interface{}, match ambiguousMatcher) {