Standard library / encoding/json

encoding/json.Decoder

Streaming JSON parser. Use Decode for values, Token/More for token traversal, and UseNumber or DisallowUnknownFields for selected decoding policies. Expected stdout: 'true\n'.

Formal Syntax & Structure

go syntaxgo
type Decoder struct {  // Has unexported fields.}

Working Example

Example Snippetgo
package main
import (  "encoding/json"  "fmt"  "strings")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  d := json.NewDecoder(strings.NewReader(`{"ok":true}`))  var x map[string]bool  must(d.Decode(&x))  fmt.Println(x["ok"])}
Go Reference