forked from mirror/gjson
GetMany result value missing, fixes #48
This commit is contained in:
parent
3c91814cf6
commit
5a69e67cfd
3
gjson.go
3
gjson.go
|
@ -1850,6 +1850,9 @@ next_key:
|
||||||
nomatch: // noop label
|
nomatch: // noop label
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !hasMatch && i < len(json) && json[i] == '}' {
|
||||||
|
return i + 1, true
|
||||||
|
}
|
||||||
if !parsedVal {
|
if !parsedVal {
|
||||||
if hasMatch {
|
if hasMatch {
|
||||||
// we found a match and the value has not been parsed yet.
|
// we found a match and the value has not been parsed yet.
|
||||||
|
|
|
@ -1086,3 +1086,18 @@ func TestGetMany47(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetMany48(t *testing.T) {
|
||||||
|
json := `{"bar": {"id": 99, "xyz": "my xyz"}, "foo": {"myfoo": [605]}}`
|
||||||
|
paths := []string{"foo.myfoo", "bar.id", "bar.xyz", "bar.abc"}
|
||||||
|
expected := []string{"[605]", "99", "my xyz", ""}
|
||||||
|
results := GetMany(json, paths...)
|
||||||
|
if len(expected) != len(results) {
|
||||||
|
t.Fatalf("expected %v, got %v", len(expected), len(results))
|
||||||
|
}
|
||||||
|
for i, path := range paths {
|
||||||
|
if results[i].String() != expected[i] {
|
||||||
|
t.Fatalf("expected '%v', got '%v' for path '%v'", expected[i], results[i].String(), path)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue