MCPcopy Create free account
hub / github.com/github/gh-aw / MarshalCompactNoHTMLEscape

Function MarshalCompactNoHTMLEscape

pkg/jsonutil/json.go:15–27  ·  view source on GitHub ↗

MarshalCompactNoHTMLEscape marshals a value to compact JSON without HTML escaping. It trims the trailing newline emitted by json.Encoder.

(v any)

Source from the content-addressed store, hash-verified

13// MarshalCompactNoHTMLEscape marshals a value to compact JSON without HTML escaping.
14// It trims the trailing newline emitted by json.Encoder.
15func 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}

Calls 2

PrintfMethod · 0.45
StringMethod · 0.45