Standard library / encoding/json
encoding/json.Encoder
Streaming JSON serializer over an io.Writer. Encode adds a newline; SetIndent and SetEscapeHTML affect subsequent writes. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
type Encoder struct { // Has unexported fields.}Working Example
Example Snippetgo
package main
import ( "bytes" "encoding/json" "fmt")
func must(e error) { if e != nil { panic(e) }}
func main() { var b bytes.Buffer var e *json.Encoder = json.NewEncoder(&b) must(e.Encode(true)) fmt.Print(b.String())}