Skip to content

Commit 38fea45

Browse files
committed
fix: obj is map[interface{}]interface{}, but the key is string, $.key can lookup value
1 parent 2e52cf6 commit 38fea45

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

jsonpath.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,14 @@ func get_key(obj interface{}, key string) (interface{}, error) {
347347
}
348348
return val, nil
349349
}
350-
for _, kv := range reflect.ValueOf(obj).MapKeys() {
351-
//fmt.Println(kv.String())
350+
of := reflect.ValueOf(obj)
351+
for _, kv := range of.MapKeys() {
352+
// obj is map[interface{}]interface{}, but the key is string
353+
if kv.Interface() == key {
354+
return of.MapIndex(kv).Interface(), nil
355+
}
352356
if kv.String() == key {
353-
return reflect.ValueOf(obj).MapIndex(kv).Interface(), nil
357+
return of.MapIndex(kv).Interface(), nil
354358
}
355359
}
356360
return nil, fmt.Errorf("key error: %s not found in object", key)

0 commit comments

Comments
 (0)