From 5a69e67cfd8f6f9b0044ed49f5079d0eeed28653 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Mon, 25 Sep 2017 04:39:06 -0700 Subject: [PATCH] GetMany result value missing, fixes #48 --- gjson.go | 3 +++ gjson_test.go | 15 +++++++++++++++ 2 files changed, 18 insertions(+) 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) + } + } +}