1package json
2
3import (
4 "bytes"
5)
6
7// Encoder is JSON encoder that supports construction of JSON values
8// using methods.
9type Encoder struct {
10 w *bytes.Buffer
11 Value
12}
13
14// NewEncoder returns a new JSON encoder
15func NewEncoder() *Encoder {
16 writer := bytes.NewBuffer(nil)
17 scratch := make([]byte, 64)
18
19 return &Encoder{w: writer, Value: newValue(writer, &scratch)}
20}
21
22// String returns the String output of the JSON encoder
23func (e Encoder) String() string {
24 return e.w.String()
25}
26
27// Bytes returns the []byte slice of the JSON encoder
28func (e Encoder) Bytes() []byte {
29 return e.w.Bytes()
30}