Fixed chained array result

This commit is contained in:
tidwall 2019-02-16 19:06:55 -07:00
parent 1ed2249f74
commit eee0b6226f
2 changed files with 20 additions and 0 deletions

View File

@ -717,6 +717,7 @@ func parseArrayPath(path string) (r arrayPathResult) {
if path[i] == '|' { if path[i] == '|' {
r.part = path[:i] r.part = path[:i]
r.pipe = path[i+1:] r.pipe = path[i+1:]
r.piped = true
return return
} }
} }

View File

@ -1485,3 +1485,22 @@ func TestModifier(t *testing.T) {
t.Fatalf("expected '%v', got '%v'", `{"HELLO":"WORLD"}`, res) 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)
}
}