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{})
| 154 | // handle them. Passing cyclic structures to Marshal will result in |
| 155 | // an infinite recursion. |
| 156 | func 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 |
no test coverage detected