Golang encoding/json.Decoder.Buffered() function example
package encoding/json
Buffered returns a reader of the data remaining in the Decoder's buffer. The reader is valid until the next call to Decode.
Golang encoding/json.Decoder.Buffered() function usage example
package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"strings"
)
func main() {
reader := strings.NewReader(`{"Name" : "Adam"} extra string to be buffered`)
var m struct {
Name string
}
decoder := json.NewDecoder(reader)
err := decoder.Decode(&m)
if err != nil {
fmt.Println(err)
}
extraString, err := ioutil.ReadAll(decoder.Buffered()) // read the remainder
if err != nil {
fmt.Println(err)
}
fmt.Println(string(extraString))
}
Output :
extra string to be buffered
Reference :
Advertisement
Something interesting
Tutorials
+31.6k Golang : Get local IP and MAC address
+29.9k Golang : Get and Set User-Agent examples
+48.5k Golang : Upload file from web browser to server
+33.7k Golang : All update packages with go get command
+10.6k Golang : Get local time and equivalent time in different time zone
+26.9k Golang : Force your program to run with root permissions
+8.8k Golang : Heap sort example
+14.2k Golang : Fix image: unknown format error
+5.6k PHP : Convert CSV to JSON with YQL example
+7.1k Golang : Squaring elements in array
+13.4k Golang : Generate Code128 barcode
+17.6k Convert JSON to CSV in Golang