diff --git a/gjson.go b/gjson.go index eba5284..a344b2d 100644 --- a/gjson.go +++ b/gjson.go @@ -717,6 +717,7 @@ func parseArrayPath(path string) (r arrayPathResult) { if path[i] == '|' { r.part = path[:i] r.pipe = path[i+1:] + r.piped = true return } } diff --git a/gjson_test.go b/gjson_test.go index 142067a..4190279 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -1485,3 +1485,22 @@ func TestModifier(t *testing.T) { t.Fatalf("expected '%v', got '%v'", `{"HELLO":"WORLD"}`, res) } } + +func TestChaining(t *testing.T) { + json := `{ + "friends": [ + {"first": "Dale", "last": "Murphy", "age": 44}, + {"first": "Roger", "last": "Craig", "age": 68}, + {"first": "Jane", "last": "Murphy", "age": 47} + ] + }` + res := Get(json, "friends|0|first").String() + if res != "Dale" { + t.Fatalf("expected '%v', got '%v'", "Dale", res) + } + res = Get(json, "friends|@reverse|0|age").String() + if res != "47" { + t.Fatalf("expected '%v', got '%v'", "47", res) + } + +}