mirror of https://github.com/tidwall/gjson.git
parent
ca5c4b1e26
commit
2feb4037b4
2
gjson.go
2
gjson.go
|
@ -584,7 +584,7 @@ func tostr(json string) (raw string, str string) {
|
|||
continue
|
||||
}
|
||||
}
|
||||
break
|
||||
return json[:i+1], unescape(json[1:i])
|
||||
}
|
||||
}
|
||||
var ret string
|
||||
|
|
|
@ -6,6 +6,7 @@ import (
|
|||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"strconv"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
@ -2086,3 +2087,36 @@ func TestBoolConvertQuery(t *testing.T) {
|
|||
assert(t, trues == "[1,2,6,7,8]")
|
||||
assert(t, falses == "[3,4,5,9,10,11]")
|
||||
}
|
||||
|
||||
func TestModifierDoubleQuotes(t *testing.T) {
|
||||
josn := `{
|
||||
"data": [
|
||||
{
|
||||
"name": "Product P4",
|
||||
"productId": "1bb3",
|
||||
"vendorId": "10de"
|
||||
},
|
||||
{
|
||||
"name": "Product P4",
|
||||
"productId": "1cc3",
|
||||
"vendorId": "20de"
|
||||
},
|
||||
{
|
||||
"name": "Product P4",
|
||||
"productId": "1dd3",
|
||||
"vendorId": "30de"
|
||||
}
|
||||
]
|
||||
}`
|
||||
AddModifier("string", func(josn, arg string) string {
|
||||
return strconv.Quote(josn)
|
||||
})
|
||||
|
||||
res := Get(josn, "data.#.{name,value:{productId,vendorId}.@string.@ugly}")
|
||||
|
||||
assert(t, res.Raw == `[`+
|
||||
`{"name":"Product P4","value":"{\"productId\":\"1bb3\",\"vendorId\":\"10de\"}"},`+
|
||||
`{"name":"Product P4","value":"{\"productId\":\"1cc3\",\"vendorId\":\"20de\"}"},`+
|
||||
`{"name":"Product P4","value":"{\"productId\":\"1dd3\",\"vendorId\":\"30de\"}"}`+
|
||||
`]`)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue