tidwall / sjson

Set JSON values very quickly in Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to disable escaping html symbols?

juev opened this issue · comments

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?

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!