MarshalCompactNoHTMLEscape marshals a value to compact JSON without HTML escaping. It trims the trailing newline emitted by json.Encoder.
(v any)
| 13 | // MarshalCompactNoHTMLEscape marshals a value to compact JSON without HTML escaping. |
| 14 | // It trims the trailing newline emitted by json.Encoder. |
| 15 | func MarshalCompactNoHTMLEscape(v any) (string, error) { |
| 16 | var buf bytes.Buffer |
| 17 | encoder := json.NewEncoder(&buf) |
| 18 | encoder.SetEscapeHTML(false) |
| 19 | if err := encoder.Encode(v); err != nil { |
| 20 | jsonutilLog.Printf("MarshalCompactNoHTMLEscape encode failed: %v", err) |
| 21 | return "", err |
| 22 | } |
| 23 | |
| 24 | result := strings.TrimSuffix(buf.String(), "\n") |
| 25 | jsonutilLog.Printf("MarshalCompactNoHTMLEscape produced %d bytes", len(result)) |
| 26 | return result, nil |
| 27 | } |