-
| I need to serve JSON responses that include full URLs containing query parameters. However, I'm encountering an issue where the URLs are being escaped—for example, characters like & and = in query parameters are converted to \u0026 and \u003d. In the Go standard library, json.Encoder.SetEscapeHTML(false) allows disabling this behavior. Is there a similar way to achieve this in Echo when using c.JSON(...), or do I need to manually handle the response to prevent escaping? |
Beta Was this translation helpful? Give feedback.
Answered by evgenybf Apr 28, 2025
Replies: 1 comment
-
| It's possible to specify your own e := echo.New() e.JSONSerializer = &MyJSONSerializer{} ...// DefaultJSONSerializer implements JSON encoding using encoding/json. type MyJSONSerializer echo.DefaultJSONSerializer // Serialize converts an interface into a json and writes it to the response. // You can optionally use the indent parameter to produce pretty JSONs. func (d MyJSONSerializer) Serialize(c echo.Context, i interface{}, indent string) error { enc := json.NewEncoder(c.Response()) enc.SetEscapeHTML(false) if indent != "" { enc.SetIndent("", indent) } return enc.Encode(i) } // Deserialize reads a JSON from a request body and converts it into an interface. func (d MyJSONSerializer) Deserialize(c echo.Context, i interface{}) error { return echo.DefaultJSONSerializer(d).Deserialize(c, i) }See how it''s implemented in Echo: |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by qulxizer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
It's possible to specify your own
JSONSerializerinstead of the default one and setenc.SetEscapeHTML(false)during serialization: