diff --git a/gjson.go b/gjson.go index 9687c0b..8e6c099 100644 --- a/gjson.go +++ b/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 diff --git a/gjson_test.go b/gjson_test.go index 25d3ee0..6bc445e 100644 --- a/gjson_test.go +++ b/gjson_test.go @@ -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\"}"}`+ + `]`) +}