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

Function Marshal

jsonxt/encode.go:156–169  ·  view source on GitHub ↗

Marshal returns the JSON encoding of v. Marshal traverses the value v recursively. If an encountered value implements the Marshaler interface and is not a nil pointer, Marshal calls its MarshalJSON method to produce JSON. If no MarshalJSON method is present but the value implements encoding.TextMar

(v interface{})

Source from the content-addressed store, hash-verified

154// handle them. Passing cyclic structures to Marshal will result in
155// an infinite recursion.
156func Marshal(v interface{}) ([]byte, error) {
157 e := newEncodeState()
158
159 err := e.marshal(v, encOpts{escapeHTML: true})
160 if err != nil {
161 return nil, err
162 }
163 buf := append([]byte(nil), e.Bytes()...)
164
165 e.Reset()
166 encodeStatePool.Put(e)
167
168 return buf, nil
169}
170
171// MarshalIndent is like Marshal but applies Indent to format the output.
172// Each JSON element in the output will begin on a new line beginning with prefix

Callers 2

MarshalIndentFunction · 0.85
stringEncoderFunction · 0.85

Calls 4

newEncodeStateFunction · 0.85
marshalMethod · 0.80
ResetMethod · 0.80
PutMethod · 0.80

Tested by

no test coverage detected