diff --git a/gjson.go b/gjson.go index 2679256..fe4143c 100644 --- a/gjson.go +++ b/gjson.go @@ -1850,6 +1850,9 @@ next_key: nomatch: // noop label } + if !hasMatch && i < len(json) && json[i] == '}' { + return i + 1, true + } if !parsedVal { if hasMatch { // we found a match and the value has not been parsed yet. diff --git a/gjson_test.go b/gjson_test.go index dfd0362..068e742 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -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) + } + } +}