MarshalJSON marshals the given value to JSON. It does not HTML escape and adds standard indentation. TODO: consider using cue's JSON marshaller instead of "encoding/json" ... it might have extra functionality related to the cue language.
(v interface{})
| 19 | // "encoding/json" ... it might have extra functionality related |
| 20 | // to the cue language. |
| 21 | func MarshalJSON(v interface{}) ([]byte, error) { |
| 22 | buff := &bytes.Buffer{} |
| 23 | e := json.NewEncoder(buff) |
| 24 | e.SetIndent("", Indent) |
| 25 | e.SetEscapeHTML(false) |
| 26 | if err := e.Encode(v); err != nil { |
| 27 | return nil, errors.WithStack(err) |
| 28 | } |
| 29 | return bytes.TrimRight(buff.Bytes(), "\n"), nil |
| 30 | } |
| 31 | |
| 32 | func unmarshalJSON(data []byte, v interface{}) error { |
| 33 | return json.Unmarshal(data, v) |