forked from mirror/gjson
Fixed chained array result
This commit is contained in:
parent
1ed2249f74
commit
eee0b6226f
1
gjson.go
1
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
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue