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)
| 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. |
| 174 | func 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 |