Documentation ¶
Overview ¶
Example ¶
package main import ( "fmt" "io" "strings" "testing/iotest" "github.com/tv42/jsonarray" ) func main() { // simulate streaming by serving reads one byte at a time stream := iotest.OneByteReader( strings.NewReader(`[{"Greeting": "hell"},{"Greeting": "o, w"},{"Greeting": "orld"}]`), ) type Message struct { Greeting string } dec := jsonarray.NewDecoder(stream) for { var msg Message if err := dec.Decode(&msg); err != nil { if err == io.EOF { break } fmt.Printf("decode error: %v\n", err) return } fmt.Printf("%s", msg.Greeting) } fmt.Printf("\nbye!\n") }
Output: hello, world bye!
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Decoder ¶
type Decoder struct {
// contains filtered or unexported fields
}
A Decoder reads and decodes JSON array items from an input stream.
func NewDecoder ¶
NewDecoder returns a new decoder that reads items of a JSON array from r. Only one item is held in memory at a time, and items are decoded as soon as they are completed, without waiting for the whole array.
type ErrNotArray ¶
type ErrNotArray struct {
Bad byte
}
ErrNotArray is the type of an error returned when the stream did not contain a JSON array.
func (*ErrNotArray) Error ¶
func (n *ErrNotArray) Error() string
type ErrNotCommaSeparated ¶
type ErrNotCommaSeparated struct {
Bad byte
}
ErrNotCommaSeparated is the type of an error returned when the array items in the stream were not comma separated.
func (*ErrNotCommaSeparated) Error ¶
func (n *ErrNotCommaSeparated) Error() string
Click to show internal directories.
Click to hide internal directories.