Fix trailing multiselector value
This commit is contained in:
parent
94e070960b
commit
c34bf81952
35
gjson.go
35
gjson.go
|
@ -1556,19 +1556,30 @@ func parseArray(c *parseContext, i int, path string) (int, bool) {
|
||||||
var jsons = make([]byte, 0, 64)
|
var jsons = make([]byte, 0, 64)
|
||||||
jsons = append(jsons, '[')
|
jsons = append(jsons, '[')
|
||||||
for j, k := 0, 0; j < len(alog); j++ {
|
for j, k := 0, 0; j < len(alog); j++ {
|
||||||
_, res, ok := parseAny(c.json, alog[j], true)
|
idx := alog[j]
|
||||||
if ok {
|
for idx < len(c.json) {
|
||||||
res := res.Get(rp.alogkey)
|
switch c.json[idx] {
|
||||||
if res.Exists() {
|
case ' ', '\t', '\r', '\n':
|
||||||
if k > 0 {
|
idx++
|
||||||
jsons = append(jsons, ',')
|
continue
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
|
if idx < len(c.json) && c.json[idx] != ']' {
|
||||||
|
_, res, ok := parseAny(c.json, idx, true)
|
||||||
|
if ok {
|
||||||
|
res := res.Get(rp.alogkey)
|
||||||
|
if res.Exists() {
|
||||||
|
if k > 0 {
|
||||||
|
jsons = append(jsons, ',')
|
||||||
|
}
|
||||||
|
raw := res.Raw
|
||||||
|
if len(raw) == 0 {
|
||||||
|
raw = res.String()
|
||||||
|
}
|
||||||
|
jsons = append(jsons, []byte(raw)...)
|
||||||
|
k++
|
||||||
}
|
}
|
||||||
raw := res.Raw
|
|
||||||
if len(raw) == 0 {
|
|
||||||
raw = res.String()
|
|
||||||
}
|
|
||||||
jsons = append(jsons, []byte(raw)...)
|
|
||||||
k++
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2016,3 +2016,10 @@ func TestModifiersInMultipaths(t *testing.T) {
|
||||||
assert(t, res.Raw == exp)
|
assert(t, res.Raw == exp)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestIssue141(t *testing.T) {
|
||||||
|
json := `{"data": [{"q": 11, "w": 12}, {"q": 21, "w": 22}, {"q": 31, "w": 32} ], "sql": "some stuff here"}`
|
||||||
|
assert(t, Get(json, "data.#").Int() == 3)
|
||||||
|
assert(t, Get(json, "data.#.{q}|@ugly").Raw == `[{"q":11},{"q":21},{"q":31}]`)
|
||||||
|
assert(t, Get(json, "data.#.q|@ugly").Raw == `[11,21,31]`)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user