DeleteBytes not working well for paths with escaped dot inside
cliu-splunk opened this issue · comments
cliu-splunk commented
I am able to read the data with gjson.GetBytes but have trouble to delete the data with sjson.DeleteBytes. See example below:
package main
import (
"fmt"
"encoding/json"
"github.com/tidwall/gjson"
"github.com/tidwall/sjson"
)
func main() {
parameters := &map[string]interface{}{
"data": map[string]interface{}{
"key1": "value1",
"key2.something": "value2",
},
}
path := "data.key2\\.something"
data, err := json.Marshal(parameters)
if err != nil {
fmt.Println(err)
}
// Read
res := gjson.GetBytes(data, path)
if !res.Exists() {
fmt.Println("res does not exist")
}
fmt.Println("res", res.Value())
// Delete
data, err = sjson.DeleteBytes(data, path)
var params interface{}
err = json.Unmarshal(data, ¶ms)
if err != nil {
fmt.Println(err)
}
fmt.Println("params", params)
}
Josh Baker commented
I just pushed a fix. Thanks for reporting.
cliu-splunk commented
Thank you!