forked from mirror/sjson
parent
fcc1b99819
commit
11cb24d842
8
sjson.go
8
sjson.go
|
@ -341,7 +341,13 @@ func appendRawPaths(buf []byte, jstr string, paths []pathResult, raw string,
|
|||
default:
|
||||
return nil, &errorType{"json must be an object or array"}
|
||||
case '{':
|
||||
buf = append(buf, jsres.Raw[:len(jsres.Raw)-1]...)
|
||||
end := len(jsres.Raw) - 1
|
||||
for ; end > 0; end-- {
|
||||
if jsres.Raw[end] == '}' {
|
||||
break
|
||||
}
|
||||
}
|
||||
buf = append(buf, jsres.Raw[:end]...)
|
||||
if comma {
|
||||
buf = append(buf, ',')
|
||||
}
|
||||
|
|
|
@ -310,3 +310,27 @@ func TestDeleteDotKeyIssue19(t *testing.T) {
|
|||
t.Fatalf("expected '%v', got '%v'", `{"data":{"key1":"value1"}}`, json)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIssue36(t *testing.T) {
|
||||
var json = `
|
||||
{
|
||||
"size": 1000
|
||||
}
|
||||
`
|
||||
var raw = `
|
||||
{
|
||||
"sample": "hello"
|
||||
}
|
||||
`
|
||||
_ = raw
|
||||
if true {
|
||||
json, _ = SetRaw(json, "aggs", raw)
|
||||
}
|
||||
if !gjson.Valid(json) {
|
||||
t.Fatal("invalid json")
|
||||
}
|
||||
res := gjson.Get(json, "aggs.sample").String()
|
||||
if res != "hello" {
|
||||
t.Fatal("unexpected result")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue