From d7c940e59395fdcaff4584cb442b2e7808f6711e Mon Sep 17 00:00:00 2001 From: tidwall Date: Sun, 30 Jun 2019 04:48:53 -0700 Subject: [PATCH] Fix missing raw result for array counts --- gjson.go | 3 ++- gjson_test.go | 4 ++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/gjson.go b/gjson.go index 8221cd9..3449983 100644 --- a/gjson.go +++ b/gjson.go @@ -1446,9 +1446,10 @@ func parseArray(c *parseContext, i int, path string) (int, bool) { if rp.alogok { break } - c.value.Raw = "" + c.value.Type = Number c.value.Num = float64(h - 1) + c.value.Raw = strconv.Itoa(h - 1) c.calcd = true return i + 1, true } diff --git a/gjson_test.go b/gjson_test.go index a871591..bc8b160 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -1911,3 +1911,7 @@ func TestSubSelectors(t *testing.T) { assert(t, Get(json, "info.friends.#.[first,extra.0]").String() == `[["Dale",10],["Roger",40]]`) } + +func TestArrayCountRawOutput(t *testing.T) { + assert(t, Get(`[1,2,3,4]`, "#").Raw == "4") +}