From 8be3ed76053f26fd17b81e19d4e15b560c253611 Mon Sep 17 00:00:00 2001 From: Josh Baker Date: Mon, 15 Aug 2016 04:56:55 -0700 Subject: [PATCH] reset count on append, fixes #3 --- gjson.go | 1 + gjson_test.go | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/gjson.go b/gjson.go index ab685e7..e61f63e 100644 --- a/gjson.go +++ b/gjson.go @@ -436,6 +436,7 @@ proc_val: // return Result{} } else { f.stype = vc + f.count = 0 stack = append(stack, f) depth++ goto read_key diff --git a/gjson_test.go b/gjson_test.go index 8b058f7..dc704bd 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -97,12 +97,24 @@ func TestEscapePath(t *testing.T) { var basicJSON = `{"age":100, "name":{"here":"B\\\"R"}, "noop":{"what is a wren?":"a bird"}, "happy":true,"immortal":false, + "items":[1,2,3,{"tags":[1,2,3],"points":[[1,2],[3,4]]},4,5,6,7], "arr":["1",2,"3",{"hello":"world"},"4",5], "vals":[1,2,3,{"sadf":sdf"asdf"}],"name":{"first":"tom","last":null}}` func TestBasic(t *testing.T) { var token Result - + if Get(basicJSON, "items.3.tags.#").Num != 3 { + t.Fatalf("expected 3, got %v", Get(basicJSON, "items.3.tags.#").Num) + } + if Get(basicJSON, "items.3.points.1.#").Num != 2 { + t.Fatalf("expected 2, got %v", Get(basicJSON, "items.3.points.1.#").Num) + } + if Get(basicJSON, "items.#").Num != 8 { + t.Fatalf("expected 6, got %v", Get(basicJSON, "items.#").Num) + } + if Get(basicJSON, "vals.#").Num != 4 { + t.Fatalf("expected 4, got %v", Get(basicJSON, "vals.#").Num) + } if !Get(basicJSON, "name.last").Exists() { t.Fatal("expected true, got false") }