tidwall / sjson

Set JSON values very quickly in Go
MIT License
2.4k stars 165 forks source link

How to disable escaping html symbols? #71

Closed juev closed 1 year ago

juev commented 1 year ago

Hello!

Thank you for your libraries!

When we get nested json and trying to create new json we got result with escaping html tags:

func run() error {
    data := `{"data":"[{\"props\":{\"text\":\"<p>test</p>\"},\"isShowValidateInfo\":false}]"}`

    fmt.Println(data)
    res := gjson.Get(data, "data")

        fmt.Println(res.String())
    templateData, err := sjson.Set("", "data", res.String())
    if err != nil {
        return err
    }
    fmt.Println(templateData)

    return nil
}

// {"data":"[{\"props\":{\"text\":\"<p>test</p>\"},\"isShowValidateInfo\":false}]"}
// [{"props":{"text":"<p>test</p>"},"isShowValidateInfo":false}]
// {"data":"[{\"props\":{\"text\":\"\u003cp\u003etest\u003c/p\u003e\"},\"isShowValidateInfo\":false}]"}

Is it possible to disable htmlEscaping?

juev commented 1 year ago

When we take a value from the received json, we get the correct value:

res2 := gjson.Get(templateData, "data")
fmt.Println(res2)
// [{"props":{"text":"<p>test</p>"},"isShowValidateInfo":false}]

Thanks!