MCPcopy Create free account
hub / github.com/blues/note / MarshalIndent

Function MarshalIndent

jsonxt/encode.go:174–185  ·  view source on GitHub ↗

MarshalIndent is like Marshal but applies Indent to format the output. Each JSON element in the output will begin on a new line beginning with prefix followed by one or more copies of indent according to the indentation nesting.

(v interface{}, prefix, indent string)

Source from the content-addressed store, hash-verified

172// Each JSON element in the output will begin on a new line beginning with prefix
173// followed by one or more copies of indent according to the indentation nesting.
174func MarshalIndent(v interface{}, prefix, indent string) ([]byte, error) {
175 b, err := Marshal(v)
176 if err != nil {
177 return nil, err
178 }
179 var buf bytes.Buffer
180 err = Indent(&buf, b, prefix, indent)
181 if err != nil {
182 return nil, err
183 }
184 return buf.Bytes(), nil
185}
186
187// HTMLEscape appends to dst the JSON-encoded src with <, >, &, U+2028 and U+2029
188// characters inside string literals changed to \u003c, \u003e, \u0026, \u2028, \u2029

Callers

nothing calls this directly

Calls 2

MarshalFunction · 0.85
IndentFunction · 0.85

Tested by

no test coverage detected