Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 7 additions & 3 deletions jsonpath.go
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,14 @@ func get_key(obj interface{}, key string) (interface{}, error) {
}
return val, nil
}
for _, kv := range reflect.ValueOf(obj).MapKeys() {
//fmt.Println(kv.String())
of := reflect.ValueOf(obj)
for _, kv := range of.MapKeys() {
// obj is map[interface{}]interface{}, but the key is string
if kv.Interface() == key {
return of.MapIndex(kv).Interface(), nil
}
if kv.String() == key {
return reflect.ValueOf(obj).MapIndex(kv).Interface(), nil
return of.MapIndex(kv).Interface(), nil
}
}
return nil, fmt.Errorf("key error: %s not found in object", key)
Expand Down
2 changes: 1 addition & 1 deletion jsonpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Test_jsonpath_JsonPathLookup_1(t *testing.T) {
if res_v, ok := res.([]interface{}); ok != true || res_v[0].(float64) != 8.95 || res_v[1].(float64) != 12.99 || res_v[2].(float64) != 8.99 || res_v[3].(float64) != 22.99 {
t.Errorf("exp: [8.95, 12.99, 8.99, 22.99], got: %v", res)
}

// range
res, err = JsonPathLookup(json_data, "$.store.book[0:1].price")
t.Log(err, res)
Expand Down